Forum Moderators: coopster
[2]
if (is_uploaded_file($_FILES['userfile']['tmp_name'])){
//Increment filename
$q = mysql_query("SELECT * FROM images");
$row = mysql_fetch_array($q);
$id = $row["id"];
$id++;
$filename = "image".$id.".jpg";
//Store image
copy($_FILES['userfile']['tmp_name'], "/usr/www/htdocs/path/img/gallery/$filename");//Save $id into database
$q = "UPDATE images SET id='$id'";
mysql_query($q);
//Resize and store thumbnail
$new_thumb = "thumb".$id.".jpg";
$sourcefile = "$_FILES['userfile']['tmp_name']";
$picsize = getimagesize("$sourcefile");
$source_x = $picsize[0];
$source_y = $picsize[1];
if ($source_x > $source_y){
$dest_x = 200;
$dest_y = 150;
} else {
$dest_x = 150;
$dest_y = 200;
}
$targetfile = "$new_thumb";
$jpegqual = 75;
$source_id = imagecreatefromjpeg("$sourcefile");
$target_id = imagecreatetruecolor($dest_x, $dest_y);
$target_pic = imagecopyresized($target_id,$source_id,0,0,0,0,$dest_x,$dest_y,$source_x,$source_y);
imagejpeg($target_id,"$targetfile",$jpegqual);
echo "File uploaded successfully.\n";
} else {
echo "Sorry, your file could not be uploaded.";
}
}
[/2]
2. Are you trying to resize GIF's? I've learned that many version of PHP don't allow GIF support because of licensing issues.
3. I just installed something similiar on my site. The script and tutorial are here (for comparison or if you want to try a different script):
[codewalkers.com...]
And I'm positive that I'm using all .jpg files to test it.
The Sql you are using looks incorrect and I think it's making the filename incorrect as well.
Have you created the /thumbs/ directory?
Permissions set correctly?
Place this line of code at the top of the script and then run the script.
error_reporting(E_ALL);
That will make PHP output all errors.
Birdman
is your MySQL connection script delivering a few errors reports
my experience with the script is that you might also
try related and full path
are you testing locally or on a production server
let us know about "error_reporting"
regards
Henry
try related and full path
The Sql you are using looks incorrect and I think it's making the filename incorrect as well.
$upload_dir = "/usr/www/htdocs/path/img/gallery/";
$file_count = count(scandir($upload_dir)) - 1;
$filename = $upload_dir."image".$file_count.".jpg";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $filename)){
//Resize and store thumbnail
$new_thumb = $upload_dir."thumb".$file_count.".jpg";
$picsize = getimagesize($filename);
$source_x = $picsize[0];
$source_y = $picsize[1];
if ($source_x > $source_y){
$dest_x = 200;
$dest_y = 150;
} else {
$dest_x = 150;
$dest_y = 200;
}
$jpegqual = 75;
$source_id = imagecreatefromjpeg($filename);
$target_id = imagecreatetruecolor($dest_x, $dest_y);
$target_pic = imagecopyresized($target_id,$source_id,0,0,0,0,$dest_x,$dest_y,$source_x,$source_y);
imagejpeg($target_id,$new_thumb,$jpegqual);
echo "File uploaded successfully.\n";
} else {
echo "Sorry, your file could not be uploaded.";
}