views:

134

answers:

2

PHP mySQL

Hi, i am having an interesting problem. I have a form in my cms that allows the admin to upload images to the server. The script resizes the images to a thumbnail (170px height)and a large image(600px height). The thumbnails are around 16000k in size and the large images are around 160,000k in size. I do not set file permissions and just let it happen automatically. When i go to the site i can see the thumbnails but i can't see the full size images and i have tracked the problem down to the file permissions. The thumbnails have rw-r-r permissions and the larger images have rw-- -- -- permissions. Ie the public does not have permission to view the large images. I save the large images with the name of the original and i save the thumbnails with _thumbnail appended to the end. Why would the permissions of the large images be different when they are both uploaded and resized by the same script and when i do not set file permissions? Does the size have something to do with it? I only get this problem when uploading images to the production server, not when working on my local machine. Thanks Andrew

A: 

I will suggest you to first look at your php.ini file

;Maximum allowed size for uploaded files.
upload_max_filesize = 10M
;Maximum size of POST data that PHP will accept.
post_max_size = 10M

The default settings would be 2M. You will need to change it like I mentioned here. If its still not working please get back.

Shiv
I can't access php.ini but i could set these values for the duration of the script right? Using ini_set?
andrew
ini_get('post_max_size') and ini_get('upload_max_filesize') should allow you to see the values.
Shiv
I don't think it is possible to change the upload_max_filesize using ini_set. The values are currentlyThe post_max_size is 8MThe upload max filesize is: 2M.Besides, it was still uploading the file, its just that the permission was changing for the larger image. I might just do what karoberts suggested and chmod files and see it that helps.
andrew
+2  A: 

How are you resizing the images? Are you using an external program?

This is just a guess, but here goes

  1. admin uploads image.jpg via your form
  2. php script writes uploaded image.jpg to file system as rw- --- --- (600)
  3. php script calls image resizer program to create image_thumbnail.jpg
  4. image resizer writes image_thumbnail.jpg as rw- r-- r-- (644)
  5. php script calls image resizer program to create resized image.jpg
  6. image resizer overwrites image.jpg, but leaves permissions as rw- --- --- (600)

To test this theory, comment out the part where it resizes image.jpg to 600px, and then check the permissions of the originally uploaded image. If they are 600, then there's your problem.

Regardless though, a simple chmod will solve your problem.

karoberts
I am using my own image resizer which simply takes the image and resizes it to the thumbnail size and the larger size and saves them to a file on the server. Would you set file permisions when you save the file to the server for each file?
andrew
yes, I would write the file, close it and then chmod it to be what I wanted
karoberts