image upload script not working with png
Posted on
16th Feb 2014 07:03 pm by
admin
The basic process of this php code is to take the submitted file, convert it to a small JPG thumbnail and put it into one directory and save the original file into another, but it seems that when using PNG images it doesn't quite work, any ideas?
Code: if((($_FILES['file']['type'] == "image/gif")
|| ($_FILES['file']['type'] == "image/jpeg")
|| ($FILES['file']['type'] == "image/pjpeg"))
&& ($_FILES['file']['size'] < 2000000000))
{
if($_FILES['file']['error'] > 0)
{
echo '<script language="javascript" type="text/javascript">window.top.window.upload_error(' . $_FILES['file']['error'] . ');</script>';
}
else
{
$fileName = $_FILES['file']['name'];
$f_ext = "." . strtolower(substr(strrchr($fileName, '.'), 1));
$time = time();
$f_noext = $time.substr(microtime(),2,3);
$f_name = $time.substr(microtime(),2,3) . $f_ext;
if(file_exists("img/" . $f_name))
{
echo $_FILES['file']['name'] . " already exists.";
}
else
{
move_uploaded_file($_FILES['file']['tmp_name'], "img/" . $f_name);
$image_path = "img/" . $f_name;
$fsize = getimagesize($image_path);
$max_d = ($orig_p==0)? 250 : 125;
$img = null;
$ext = strtolower(end(explode('.', $image_path)));
if($ext == 'jpg' || $exit == 'jpeg')
{
$img = @imagecreatefromjpeg($image_path);
}
else if($ext == 'png')
{
$img = @imagecreatefrompng($image_path);
}
else if ($ext == 'gif')
{
$img = @imagecreatefrompng($image_path);
}
if($img)
{
$w = imagesx($img);
$h = imagesy($img);
$width = imagesx($img);
$height = imagesy($img);
$scale = min($max_d/$width, $max_d/$height);
if($scale < 1){
$new_width = floor($scale *$width);
$new_height = floor($scale*$height);
$tmp_img = imagecreatetruecolor($new_width, $new_height);
imagecopyresized($tmp_img, $img, 0,0,0,0,$new_width,$new_height,$width,$height);
imagedestroy($img);
$img = $tmp_img;
ImageJPEG($img, 'thumb/' . $f_noext . 't.jpg',60);
imagedestroy($tmp_img);
echo '<script language="javascript" type="text/javascript">window.top.window.stopUpload();</script>';
}
}
}
}
}
No comments posted yet
Your Answer:
Login to answer
50
8
Other forums
Need help making a script that moves data into acrhive table
Hi,
I'm kinda new to php/mysql
And i wrote a simple script to store sales lead for a b
Pagination won't carry results past page 2.
Hi all,
I've worked out my pagination script and its paginating fine until I click next from
Creating Images from images in PHP
Okay well I am trying to make a 'dynamic' calender image with PHP.
I have images like this:
GMail like Chat in ASP.NET
Hi,Can anyone suggest me, how to incorporate GMail like chat in my existing ASP.Net application.I wa
Values disappear from my array :( HELP!
hey all, I have a lil mysql/php/apache script that queries a database
and pulls put 5 integers.
Comparing MySql data and arrays.
I have a mysql table set up like this:
idsubjectbodyuseriddatetimetags1blog subjectblog body111|2
Reading Most Recent CSV File in Directory
I thought I had wrapped this project up, but found out that the program I use to FTP a csv file to m
Need help to identify this error please
:confused:Can anyone help me tell what this error message means? Maybe tell me where to look to fix
Please help understand this code
I noticed the index page on my site was modified this morning and found this code inserted at the bo
FFmpeg Images 2 Video conversion problem ??
I got folder full of images , number of images = 600 , I want to make a video which plays one image