I am resizing an uploaded image and I want to store it in a folder with a random code (called $random).
But, I also want to change the filename of the uploaded file to the same random code.
But, where in this script can I make this?
I want the thumbnail image to be stored in the random code folder with the name $random.jpg
Well, it does, but as I previously mentioned your function doesn’t have access to $random. You need to use global $random; (first line in your function) or pass $random to your function as an argument process_image_upload($field, $random)
Hmmm, I still don’t get it. There is no file name attached to the thumbnail.
The only thing I have after the above code, is this:
Is there anything I need to change there as well?
One page is handling the form for the upload. Then the user ends up on this page and the resize and upload process is handled.
And this is where I want the $random to replace the original filename. Then the image is supposed to end up in a folder with the $random as folder name and the image stored in that folder with the $random as file name with .jpg added.
But, after doing what you wrote above, I still just get an image called .jpg
$result = process_image_upload('Image1');
if ($result === false) {
echo '<br>An error occurred while processing upload';
} else {
echo '<br>Uploaded image saved as ' . $result[0];
echo '<br>Thumbnail image saved as ' . $result[1];
}
Of course that had to be changed as well. Now it’s working.
I said I was stupid, right?
Thanks a lot… sometimes my head is spinning the wrong way and I start thinking about other things.
Or maybe too many projects running at the same time…