Jump to content

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

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.