Jump to content

Resizing Image


mike12255

Recommended Posts

I have the following code:

 

<?php

ini_set ("display_errors", "1");
error_reporting(E_ALL);

//this returns the name of the image
$name = $_FILES['uploadfile']['name'];
//get the extension of the image
$ext = substr($name,-3);
//We will add some secruity here, make sure the extension is an image file extension
if($ext == "gif" || $ext == "jpg" || $ext == "png" || $ext == "peg"){

//The part the user selected to insert the image into
$area = $_POST['catagory'];
//more security, make sure 'catagory' is actually a choice offered and not a mysql query (or something else entered)
if (!in_array($area, array("Sofas","Beds and Bunks","Dressers and Cabinets","Side Tables and Desks"))) {
header ("Location: index.php");
}
//set vars in here
$wantedname = $_POST['name'];

// This is the temporary file created by PHP
$uploadedfile = $_FILES['uploadfile']['tmp_name'];

//below changes the files name
if ($name != $wantedname){	
$name = $wantedname;
}

list($width,$height)=getimagesize($uploadedfile);
$newwidth = 100;
$newheight = 100;
//copy the file to were we want it now
//die($name);
rename("$uploadedfile", "images/" . $area . "/". $name . $ext);

//lets resize it now!!
$path = "images/$area"."/". $name . "." . $ext;
$src = imagecreatefromjpeg($path);
list($width,$height)=getimagesize($path);
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);


}else{
header ("Location: index.php");	
}
?> 

 

and i had it working, but no for some reason it dosnt work i get these following errors:

 

 

Warning: imagecreatefromjpeg(images/Sofas/noonewouldusethis.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home/schoolw1/public_html/kaon/upload.php on line 39

 

Warning: getimagesize(images/Sofas/noonewouldusethis.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/schoolw1/public_html/kaon/upload.php on line 40

 

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/schoolw1/public_html/kaon/upload.php on line 42

Link to comment
https://forums.phpfreaks.com/topic/149567-resizing-image/
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.