I am trying to upload an image and at the same time copy the file to another directory where i hope to then create that into a thumbnail size image.
The idea is to basically build a dynamic photo album so the output is a loop of images thats gets automatically updated every time someone uploads to it.
The main image i can upload without any problems, and the output loop is also easy. But i would love to be able to copy and thumb the image at the same time I upload and insert the file, file name and info to the directory and DB.
I have been trying to run a copy after the files uploads and then i was planning to test a Imagick to thumb the second img. But i havent even got around to testing the thumb yet because my copy doesnt work.
If all else fails I will just have to use Timthumb but I would expect that to load much slower on the output page. Does anyone have any issues with Timtumb? That would be a hell of a lot easier. :)
Basically I have this
if(move_uploaded_file($_FILES['thefile']['tmp_name'], 'uploads/' . $_FILES['thefile']['name'])) {
$photo_filename = $_FILES['thefile']['name'];
$query = "INSERT INTO gallery_photos (
photo_filename
) VALUES (
'{$photo_filename}'
)";
$result = mysql_query($query, $connection);
$path = 'http://mydomain.com/directory/uploads/';
$fpath = $path.$photo_filename;
$dest = 'http://mydomain.com/directory/thumbs/';
$fdest = $dest.$photo_filename;
copy($fpath, $fdest);
if ($result) {
redirect_to("new_photo.php?upload=4");
} else {
echo "<p>Dude. Something went wrong!</p>";
echo "<p>" . mysql_error() . "</p>";
}
}
I tried several variations of this, i placed the copy above the SQL and below, I also tried it without the $path/$dest variables i also tried it originally without the full path. But none of them worked.
The main pics are being uploaded to the uploads folder though. Its just not getting copied. The DB is getting updated no worries too.
Any help will be much appreciated.
Cheers
I think your copy process should look like this
$path = __DIR__; // Full Path to site NOT URL
$fpath = $path . "/uploads/" . $photo_filename;
$fdest = $path . "/thumbs/" . $photo_filename;
if (! is_file($fpath))
trigger_error("File Does not exist");
if (!is_writable(dirname($fdest)))
trigger_error("Can not Write to Destination");
copy($fpath, $fdest);