I'm hoping someone can help me on this. Ive been using this piece of code for years, but my webserver just got upgrade to PHP5, and now I cant upload any images!!
I'm guessing that some elements are no longer compatible in PHP, but havent a clue where to start. Maybe someone with a better trained eye can spot something, apart from my terrible coding skills. Any help would be greatly appreciated.
// ....................................... MY UPLOAD SCRIPT STARTS//
define ("MAX_SIZE","5000000000");
define ("WIDTH","400");
define ("WIDTHth","75");
function make_thumb($img_name,$filename,$new_w,$new_h)
{
$ext=getExtension($img_name);
if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
$src_img=imagecreatefromjpeg($img_name);
if(!strcmp("png",$ext))
$src_img=imagecreatefrompng($img_name);
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
$ratio1=$old_x/$new_w;
$ratio2=$old_y/$new_h;
if($ratio1>$ratio2) {
$thumb_w=$new_w;
$thumb_h=$old_y/$ratio1;
}
else {
$thumb_h=$new_h;
$thumb_w=$old_x/$ratio2;
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if(!strcmp("png",$ext))
imagepng($dst_img,$filename);
else
imagejpeg($dst_img,$filename);
imagedestroy($dst_img);
imagedestroy($src_img);
}
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$errors=0;
if(isset($_POST['btn_welcomepic']))
{
$image=$_FILES['nwbpswelcomepic_pic']['name'];
if ($image)
{
$filename = stripslashes($_FILES['nwbpswelcomepic_pic']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png"))
{
echo '<h1>Unknown extension!</h1>';
$errors=1;
}
else
{
$size=getimagesize($_FILES['nwbpswelcomepic_pic']['tmp_name']);
$sizekb=filesize($_FILES['nwbpswelcomepic_pic']['tmp_name']);
if ($sizekb > MAX_SIZE*1024)
{
echo '<h1>You have exceeded the size limit!</h1>';
$errors=1;
}
$image_name=time().'.'.$extension;
$newname="test/".$image_name;
$copied = copy($_FILES['nwbpswelcomepic_pic']['tmp_name'], $newname);
if (!$copied)
{
echo '<h1>Copy unsuccessfull!</h1>';
$errors=1;
}
else
{
$imgphoto='photo_'.$image_name;
$thumb_name='../../../images/welcome/photo_'.$image_name;
$thumb=make_thumb($newname,$thumb_name,WIDTH);
$imgthumb='thumb_'.$image_name;
$thumb_name='../../../images/welcome/thumb_'.$image_name;
$thumb=make_thumb($newname,$thumb_name,WIDTHth);
$deleteimagefile="../../../images/welcome/".$image_name;
unlink($deleteimagefile);
}} }}
// ....................................... MY UPLOAD SCRIPT ENDS//