11-03-2007, 10:10 PM
I'm new to PHP, can anybody enlighten me on how I can get PHP to upload any image file, store the image path in a database for later use, resize the image to the following dimensions (keeping aspect ratio), then overwrite the original with the resized image.
11-04-2007, 01:23 AM
That's a lot to swallow, but start with imagecopyresampled() (http://www.php.net/manual/en/function.imagecopyresampled.php) which also requires you know how to create images using functions such as imagecreatefromjpeg() (http://www.php.net/manual/en/function.imagecopyresampled.php).
Uploading files is a whole other animal... start here with this page (http://www.php.net/manual/en/features.file-upload.php) in the manual.
11-04-2007, 03:58 AM
Using PHP GD libraries ... see Fumigator's links.
It takes a bit of practice and experimentation to get it to work.
There are some good examples though.
For the "program flow", I suggest doing it this way ...
1) Use a typical PHP script to upload the image into a "temp" directory.
2) After the upload, redirect to another PHP script that takes the
image, resizes it and saves it in the final directory and deletes the
3) It then writes the final path into the database.
The reason I like using the intermediate temp directory is to avoid
corrupting the final directory in the event something fails in the script.
You can search Google for "PHP file upload script" to get that part,
then use the GD examples and tutorials to get the resize part.
The part where it saves into the final directory is done with GD, and
the deleting from the temporary directory is done using "unlink".