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

If all else fails, read the instructions (or at least the FAQ)

My phpShop hacks and modules

Re: A guide to image upload problems

If (heaven forbid!) your images get deleted or corrupted on the server, you will have lots of "fun" replacing them. Here's what will happen...

You will try to replace the lost image using the product form in administration to update the product with the image. However, the script will get the previous image name from the db and try to delete it first. Oh no! It's not there - error!

You could always go through the db and remove every image name from the product table, but that would be rather laborious. It would be much easier if your local images were the same name as the ones on the server so you could just ftp the replacements, right?

Here is a slight modification I have made to the validate_image() function which generates more logical image names.

I have designed it to do the following:
For product thumb images, the file name will be:
"product_t_" plus the product sku plus ext (e.g. product_t_hi1234.gif)
For product full images, the file name will be:
"product_f_" plus the product sku plus ext (e.g. product_f_hi1234.gif)
For vendor thumb images, the file name will be:
"vendor_t_" plus the vendor_id plus ext (e.g. vendor_t_vi9876.gif)
For vendor fullimages, the file name will be:
"vendor_f_" plus the vendor_id plus ext (e.g. vendor_f_vi9876.gif)

Here's what to do....

Open admin/lib/ps_main.inc and find the validate_image() function

Find the following code (~line 82):[code]

If all else fails, read the instructions (or at least the FAQ)

My phpShop hacks and modules

Re: A guide to image upload problems

Hi John,



I think your guide helped me narrow down my problem.  Anyways, I think the reason most people including myself are getting the Cannot delete, upload, or write to Errors is because they do not have appropriate access to the shop_image/vendor and shop_image/product folder.



Because on my local machine I never got any of these ERRORS, when I decided to host my webstie with a hosting service I started getting these ERRORS.  Then I comment the section that checks if the folder is writeable, and I got the following error from my hosting server:



SAFE MODE Restriction in effect. The script whose uid is 531 is not allowed

to access /var/www/html owned by uid 0



I think I found a solution to error I got from the hosting server at the following post:

http://www.phpshop.org/phpbb/viewtopic.php?t=3401



In which Dmitry said to do the following:

php engine should be configured with

safe_mode = on

safe_mode_gid = off

in php.ini OR with following in httpd.conf (if used as apache module)

php_admin_value safe_mode 1

php_admin_value safe_mode_gid off



I asked my hosting service provider if they can make the above changes for me, but I am not sure if that is the solution to my problem.

Note: They are using Linux server and

Permissions are set:

777 shop_image

777 shop_image/product

777 shop_image/vendor



Any help would be appreciated. smile



Thank You all,

Re: A guide to image upload problems

i think this is a good idea - also a plus might be improved se returns with image names mirroring relevant info to the product...??

Re: A guide to image upload problems

Firstly, I cannot advise on server related questions because I do not have that knowledge.



There is another method which could be used to upload images - especially if you are running the store yourself.



Simply change the product form's 'file' fields to 'text' fields.



Then remove the validate_image() and process_images() function calls in ps_product.inc



Then you would...

1) Name all your product images uniquely on your local machine (maybe using the sku)

2) FTP all the images to the product folder

3) In the product form, enter the file name into the text fields.



Would speed up product adding, but has the potential for error when typing the name into the field. Would also potentially allow the use of the same image for more than one product.



-John

If all else fails, read the instructions (or at least the FAQ)

My phpShop hacks and modules

Re: A guide to image upload problems

Images that I try to upload for products are being mysteriously renamed in the product table.  This is not apparent from the admin product form where the image remains blank but when I look at the product table with MySQLAdmin it is named something like ef3b1c063ded7161798d83c0ed78c189.gif.  I have chmod -R 777 shop_image.



I am trying to upload an image called blank.gif that is located on my desktop.   I have even tried to upload blank.gif directly into the shop_image directory and then typed in blank.gif on the admin product page.  Still the same odd renaming.



Renaming the relevant columns in the product table with MySQLAdmin does work.

Re: A guide to image upload problems

Yes, when you use the file upload fields in the product form, the script does rename the file and puts the new name in the product table. The newly named file should be in the shop_image/product folder.



-John

If all else fails, read the instructions (or at least the FAQ)

My phpShop hacks and modules

Re: A guide to image upload problems

Hi



I have done the chmod 777 to the vendor directory under shop_image and successfully

updated the vendor_image. However, all the previous shown product images disappeared.

Could anyone help me  ?





Tommy

Re: A guide to image upload problems

Thers an aditional problem with the upload problem.



I u first enter none as image, then later change to an image for that product, your dummy image for none will be deleted. The next product u try to change from none to an image will then not validate the old image and u will be unable to change image.



Sorry about the english.



If i find a bug fix i will post it later.



Georg

Re: A guide to image upload problems

JohnS,



Your guide is very much appreciated, but I have one question.



Does it cater for multiple images as well ? .. if I am using

multiple images say, 5 per product. What changes do I have

to make to the codes ?



Thanks a lot.

Dhon

"Successful people are always looking for opportunity to help others"

~Brian Tracy~

Re: A guide to image upload problems

If you are using the original method of validating images, all you should need to do for each additional image is:

1) Add a field for it in the product table

2) Add an image field to the product form, naming it the same as the db field it should go in.

3) In the validate() function of ps_product.inc, copy the call to the validate_image() function, but replace the field name (e.g. "product_full_image" with the new field name.

4) In the add() and update() functions of ps_product.inc, add the new field to the query.

5) Add the new image to the validate_delete() function of ps_product.inc (i.e. Add the field name to the select query and copy the validation).



I have not tested this, but I think it should work.



-John

If all else fails, read the instructions (or at least the FAQ)

My phpShop hacks and modules

Re: A guide to image upload problems

Hi John,



I followed your instructions step by step and encountered no error so far,

but I know I am being dumb again .. to ask this ..



I believe some code changes must take place in the admin/lib/ps_main.inc  as well rite ? the question is how ??



I did try adding the new image to a particular item, once I checked the table, instead of the default NULL value of the new field value .. the value is now .. a blank space. What am I missing here John ?

Please please enlighten me .. I know I am close to the getting it to work ..

but just dont know how ..



Thanks for your help and patience!  :oops:



Dhon



ps: please tell me if i need to post some of my codes for you to see ..

"Successful people are always looking for opportunity to help others"

~Brian Tracy~

Re: A guide to image upload problems

No, you shouldn't need to modify the function, but I do see something else I missed....

In index.php you will see the lines:[code]

If all else fails, read the instructions (or at least the FAQ)

My phpShop hacks and modules

Re: A guide to image upload problems

Finally,

I made it work .. John. Thanks to you.
I am now able to add in multiple images and with some changes to the naming.

Previously; according to John:

e.g. for product with sku "hl8823" you would create the following images:
product_t_hl8823.gif (for thumb)
and
product_f_hl8823.gif (for full)

Due to the fact that I need to add in multiple images, I tweaked John's codes in admin/lib/ps_main.inc

Now the code looks like:


[code]

$to_file = $table_name;

"Successful people are always looking for opportunity to help others"

~Brian Tracy~

Re: A guide to image upload problems

Hey it just my function  don't serious
yikes  yikes  yikes  big_smile  yikes  yikes  yikes
-------------------------------------------------------------------------
[code]


function validate_images(&$d,$path,$input,$rm="") {
    global $HTTP_POST_FILES;

    $d[$input] = "";
    if(!$HTTP_POST_FILES[$input]['name']){

Re: A guide to image upload problems

Hi everyone,
I am trying to fix image upload problem from a WEEK without any luck.
I am running Apache 1.3/PHP4.0 on Win XP.
I followed all code changes, but  still get the same nasty errors:

"ERROR: Cannot read uploaded thumbnail image temp file." - when try to update product, and

"ERROR: Cannot read uploaded thumbnail image temp file." when try to add a new product.

I'm giving up :unsure:
Any help will be greatly appreciated.

Re: A guide to image upload problems

Okay, this is my first post, and I've read around and didn't find this problem addressed, and check multiple tutorials, but here's my problem.

I'm building a website for my work, and we don't sell things like. . hand shovels, circular saw, hammer. . you get the picture. So I want to delete these objects, and start uploading our product (1500+ not fun for me).

Do I click on one, go down to delete the object, and i get this error.

ERROR: Cannot delete from thumbnail image directory.
/home/{REMOVED NAME}/public_html/phpshop/../phpshop/shop_image/product/

It's the same when I try to upload a new product image for something I want up there. Am I missing something? I tried to CHMOD and that didn't seem to help any.

Any advice would be great. . .

Lord Thaddius the frustrated.. .

Re: A guide to image upload problems

First clue: the strange directory structure.

Why is '/phpshop/../phpshop' in the path?

That which is, is; that which is not, is not; that which is, is not that which is not; that which is not, is not that which is.

Re: A guide to image upload problems

That's a very good question, and I was actually wondering the same thing. . .this may sound like a retarded question, but where do I look to find where the images are pointed too? Then I'll change that, hopefully it would help.

Lord Thaddius the bewildered.

Re: A guide to image upload problems

Looks like you have vendor_image_path set incorrectly.

The path is made up as follows....

WEBROOT . vendor_image_path . "product/"

From the look of your path, WEBROOT is
/home/{REMOVED NAME}/public_html/phpshop/

and vendor_image_path is
../phpshop/shop_image/

In the store form, set vendor_image_path to be relative to where index.php is. Probably should be: shop_image/

John

If all else fails, read the instructions (or at least the FAQ)

My phpShop hacks and modules

Re: A guide to image upload problems

Okay, took your advice, and now it's at least pointing in the right direction, however, it's still giving me an error.

Says this when I try to delete an item:
ERROR: Cannot delete from thumbnail image directory.
/home/{REMOVED}public_html/phpshop/shop_image/product/

Says this when I try to add an item:
ERROR: Cannot write to thumbnail image destination directory.
/home/{REMOVED}/public_html/phpshop/shop_image/product/
ERROR: Cannot write to full image destination directory.
/home/{REMOVED}/public_html/phpshop/shop_image/product/

Okay, and here's something freakin annoying and . . . slightly unnerving. When I open the shop/shop_image/products folder, it crashes whatever is opening it (ie WS_FTP, CuteFTP XP, DreamWeaver(totally screwed that up), Adobe Photoshop 7 and Explorer). What's up with that? If you know. . .

Lord Thaddius. . pretty POed about now

Re: A guide to image upload problems

Is the folder chmod 777?

John

If all else fails, read the instructions (or at least the FAQ)

My phpShop hacks and modules

Re: A guide to image upload problems

Yup, it's CHMOD to 777, but that's not helping either. Thanks for your help and stuff though. I appreciate it. However, I'm about 30 seconds away from scrapping phpShop and find something else. . .

Thanks.

Lord Thaddius. . .

Re: A guide to image upload problems

Ok, I just noticed something....

You mentioned the shop/shop_image/products folder.

The shop_image folder should not be in the shop folder. Move it to the same folder that index.php is in and reaffirm that shop_image/products and shop_image/vendor are both chmod 777.

If it still won't work, delete everything from the shop_image/product folder, clear all the image names from the product table and start from there.

John

If all else fails, read the instructions (or at least the FAQ)

My phpShop hacks and modules

Re: A guide to image upload problems

Awesome. . that worked. Now that it was so. . blatently. . easy, I feel stupid. Thanks alot JohnS, I really appreciated your help.

Lord Thaddius the content.