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
problem with script manager
Hi iam using Net.2005.I have created ajax enabledwebsite.i have master page in which i have script m
Problem with PHP code- simple contact form
Hi Folks,
I'm relativily new to PHP; I know HTML and CSS stuff but I have a problem- I have a co
PHP loop
Okay so I have several "articles" stored in a mysql database and am attempting to echo tho
form problem
Hi all, I think this is going to be easy to resolve but for I have been looking at it to long and I
PHP Script runs on CLI but not through web browser
I am running into an issue that I just can't seem to find the answer to. I have a Windows Server 200
Will this protect from mysql injection?
I do not want anything like DROP TABLE to work or any type of coding..
Heres my code.. is it
Generate multilayered array from string.
ok so i have a string that looks like this:
Code: blog:edit_all,delete_all|users:edit_all,delete_
reorder sql query
ok so i have this very simple code:
Code: $query = "SELECT search_keywords, COUNT(search_key
mail with attachment problems
Hi. I have the following code:
Code: else if(file_exists("site".$timp.".zip")
filesize problem
i use ubuntu 9.10 and i have mountet a folder from an windows
/mount/FOLDER
/mount/FOLDER/