Jump to content

php resize upload image


40esp

Recommended Posts

I have this code:

 

<?php // Upload and Resize Image
$uploadedfile = $_FILES['add_photo']['name'];
$src = imagecreatefromjpeg($uploadedfile);
list($width,$height)=getimagesize($uploadedfile);
$newwidth=103;
$newheight=131;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$filename = "../upload/($height/$width)*600($height/$width)*600($height/$width)*600($height/$width)*600". $_FILES['add_photo']['name'];
$image_val = basename( $_FILES['add_photo']['name']);
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp); ?>

 

i beleive it uploads correctly, except when the conversion takes place, the final output is a 103 x 131 just Like I wanted, but it a 1kb black image. I made sure it was a jpeg aswell. What am I doing wrong?

 

what I'm doing is having an upload form submit an image, resize it, write it to the disk, then generate the filename so that I can use it in a mysql insert query.

Link to comment
https://forums.phpfreaks.com/topic/108920-php-resize-upload-image/
Share on other sites

I believe that using $_FILES['add_photo']['name'] will only give you the files name and isnt actually on the server a file the server can read..

Try using $_FILES['add_photo']['tmp_name'] which is where the file is stored for you to use in scripts such as this.

 

So if you want to resize the image use $_FILES['add_photo']['tmp_name']

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.