Topic: A guide to image upload problems
When uploading an image, the validate() function calls the validate_image() function in ps_main.inc, e.g. when updating the vendor details, the call looks like this:
validate_image($d,"vendor_thumb_image","vendor")"vendor" is the folder the image is to go into
"vendor_thumb_image" is the name of the vendor form's "file" field for the thumbnail image
If an error occurs, the script will replace the _ with a space and use that in the error message, e.g. 'vendor_thumb_image' will become 'vendor thumb image' in the error message.
The next thing the function does is generate the path to the directory the image has to go to.
If the form sends an image path, it uses that.
Otherwise, if $ps_vendor_id is set, it uses that
Otherwise, if the form sends a vendor_id, it uses that.
Otherwise, the following error occurs:
ERROR:process_image: Could not resolve vendor image path.If the path resolves ok, the folder (e.g. 'vendor') is concatenated to it. So you end up with a path like...
WEBROOT . vendor_image_path . folder
or, for example,
/path/to/web/root/shop_image/vendor/If you are deleting the original image (i.e. you entered "none" into the field), the script checks whether or not the path (above) exists and is writable. If not, you get the following error:
Cannot delete from [image_type] directory.
[path] (where image_type is, for example, 'vendor thumb image')
(And path is, for example, '/path/to/web/root/shop_image/vendor/')
If you are uploading a new file, it first checks that the uploaded file is readable. If not, you will get the following error:
ERROR: Cannot read uploaded [image_type] temp file. Next it generates a unique filename for the image.
Then it checks to see what 'type' of file you uploaded. If it is a .gif, .jpg, or. png, it will concatenate that to the unique image name. If the uploaded file type is not one of those, you will get the following error:
ERROR: [image_type] file is invalid. Next, it checks if the path the image is to go to is writeable. If not, you will get the following error:
ERROR: Cannot write to [image_type] destination directory.
[path]If all is well so far, unlink (delete) and copy commands are generated and added to an array to be used in the process_images() function which loops through the array and evals each command.
If any of the commands fail, you will get the following error:
ERROR: Image Update command failed.
[command]Hope this helps someone
-John
