Jump to content

file upload image dimension amend


ben_johnson1991

Recommended Posts

Hey, I have never used any functions before in an image file to amend it, apart from the name.

 

Please could I get a hand in scripting code so that I can changed the file dimensions, with a bit of notes, so i understand what is what.

 

my current script is basically

PHP Code:

$photo1 = $photo1 = $_FILES['photo1']['tmp_name'];

 

Then this to validate

 

if (!$_FILES['photo1']['tmp_name']) {

 

$photo1Error = '* You Must Submit Atleast <strong>One Image</strong> <br />';

$errorStat1 = '1';

$photoStat1 = '0';

 

} else {

 

list($width,$height)=getimagesize($photo1);

 

$newwidth=268;

$newheight=($height/$width)*$newwidth;

$tmp=imagecreatetruecolor($newwidth,$newheight);

 

imagecopyresampled($tmp,$photo1,0,0,0,0,$newwidth,$newheight,

$width,$height);

 

$photo1 = $_FILES['file']['tmp_name'];

 

 

$maxfilesize = 524288; // 524288 bytes equals 0.5MB

if($_FILES['photo1']['size'] > $maxfilesize ) {

 

$photo1Error = '* <strong>Image1</strong> was too large (0.5MB max) <br />';

$errorStat1 = '1';

$photoStat1 = '0';

unlink($_FILES['photo1']['tmp_name']);

 

} else if (!preg_match("/\.(gif|jpg|jpeg|png)$/i", $_FILES['photo1']['name'] ) ) {

 

$photo1Error = '* <strong>Image1</strong> was not one of the accepted formats (.jpg/.jpeg/.png/.gif) <br />';

$errorStat = '1';

$photoStat1 = '0';

unlink($_FILES['photo1']['tmp_name']);

}

$photoStat1 = '1';

}

 

 

and finally

 

if($photoStat1 == 1){

$newname = "image01.jpg";

$place_file = move_uploaded_file( $_FILES['photo1']['tmp_name'], "classifieds/$id/".$newname);

}

to upload.

 

When I submited this, i recieved te following error

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/bensboxc/public_html/volkslove/regclassified.php on line 143

 

line 143 is '''' $width,$height);''''

 

 

 

any suggestions where im going wrong would be great,

thanks!

Link to comment
https://forums.phpfreaks.com/topic/194407-file-upload-image-dimension-amend/
Share on other sites

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.