Web Hosting Talk







View Full Version : Resizing images with convert?


Amish_Geek
01-21-2005, 01:29 AM
Ok, for some reason, my PHP code is no longer working. Can someone take a look at my code and see if anything is wrong? It used to work, but now it doesn't, and I'm trying to figure out how to get it to work again.

Basically, when a user uploads a file, it puts it in the /pics/ dir, and this script then makes a 200x200 thumbnail of it.

I've edited the system path. The script uploads the file just fine, however, it is echoing that it is not able to create the thumbnail.



if (!is_uploaded_file($userfile)) {
echo "Problem: Possible file upload attack";
exit;
}

$upfile = "/path/to/pics/".$go."-".$userfile_name;
$thumbfile = "/path/to/pics/thumbs/".$go."-".$userfile_name;

if (!copy($userfile, $upfile)) {
echo "Problem: Could not move file into directory";
exit;
} else {

$execcmd = "convert -geometry 200x200 " . $upfile . " " . $thumbfile;
echo $execcmd."<hr>";
if (!exec($execcmd)) {
echo "Thumb could not be created";
}


Sorry for the tabs, I copied it right out of dreamweaver.

John[H4Y]
01-21-2005, 04:02 AM
Looks like you are using ImageMagick's "convert" command by calling it through PHP's "exec" function. It could be that your host is being smart and has disabled this dangerous function.
I don't know off the top of my head if when the exec function executes a command that ends up exiting with an error (such as "no such file or directory") , if the exec function will then return false. If so, it could be that ImageMagick was removed from your server or that directory permissions have changed so that the PHP user is unable to write to it.