Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 08-11-2009, 03:08 PM Image upload code
Junior Talker

Posts: 2
Name: Peter
Trades: 0
Hello,

I don't suppose any one can give me any idea what is wrong with this piece of code? As much as I can work out it's the imagecreatetruecolor part which isn't working but I'm not sure why?



if ($_FILES["file"]["name"] != "") {

if (file_exists("images/gallery/" . $return . "_" . $_FILES["file"]["name"])) {
echo "<font color=red>" . $_FILES["file"]["name"] . " already exists. </font>";
} else {
echo $_FILES["file"]["tmp_name"];

switch ($_FILES["file"]["type"]) {
case "image/gif": $im = imagecreatefromgif($_FILES["file"]["tmp_name"]); break;
case "image/jpeg": $im = imagecreatefromjpeg($_FILES["file"]["tmp_name"]); break;
case "image/png": $im = imagecreatefrompng($_FILES["file"]["tmp_name"]); break;
default: trigger_error('Unsupported filetype!', E_USER_ERROR); break;
}

$dir = "/images/gallery/thumb_" . $return . "_" . $_FILES["file"]["name"];
$width = imagesx($im);
$height = imagesy($im);
$x = 100;
$y = 100;
$dst = imagecreatetruecolor($x,$y);
imagecopyresampled($dst,$im,0,0,0,0,$x,$y,$width,$ height);

switch ($_FILES["file"]["type"]) {
case "image/gif": imagegif($dst, $dir); break;
case "image/jpeg": imagejpeg($dst, $dir); break;
case "image/png": imagepng($dst, $dir); break;
default: trigger_error('Failed resize image!', E_USER_ERROR); break;
}

}
}

$return is a variable from a function I've used just before this.

Any help would be great, Thanks
PeterUK21 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-12-2009, 03:20 PM Re: Image upload code
EdB
Skilled Talker

Posts: 79
Name: Ed Barnett
Trades: 0
Is there a particular error code popping up at all?
__________________

Please login or register to view this content. Registration is FREE
EdB is offline
Reply With Quote
View Public Profile Visit EdB's homepage!
 
Old 08-12-2009, 03:46 PM Re: Image upload code
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
There is a space between $ and height in the imagecopyresampled() function call. If that doesn't fix it, as Ed said, is there any errors or warnings given?
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Reply     « Reply to Image upload code
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29816 seconds with 12 queries