Jump to content

Recommended Posts

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//

Edited by PFMaBiSmAd
added code tags
Link to comment
https://forums.phpfreaks.com/topic/271215-php4-to-php5-image-upload/
Share on other sites

I dont seem to be experiencing any errors. I monitor my internet after i hit the submit button; it clearly uploads in some way or form, and IE loads the following page to say upload complete. The destination folder permissions are correct, but nothing appears in the folder. It's left me rather puzzled.

 

http://www.wiltonandbarfordprimaryschool.co.uk/phpinfo.php

IE loads the following page to say upload complete

 

Since nothing you posted shows how your code is going to a 'following' page, your first step would be to post all the relevant code needed to reproduce the problem.

 

Best guess (as a general rule don't expect people to visit links you put in your posts) is you have output buffering turned on in your master php.ini and this is hiding any messages you are displaying and your code is unconditionally redirecting to your 'following' page.

Edited by PFMaBiSmAd
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.