Image permissions 0000
24 posts
• Page 1 of 2 • 1, 2
Image permissions 0000
I'm not sure if this is an OC issue or a host issue, but since upgrading from 0.7.8 to 0.7.9RC5 all the images I upload via OC have permissions set at 000 and I have to change them through my host (hostmonster). Is anyone else having this trouble?
- djbrock
- Posts: 48
- Joined: Thu Dec 04, 2008 2:37 pm
Re: Image permissions 0000
Is this similar to this:
http://forum.opencart.com/index.php/top ... ml#msg8236
http://forum.opencart.com/index.php/topic,1891.0.html
If so a solution was posted here:
http://forum.opencart.com/index.php/topic,2367.0.html
http://code.google.com/p/open-cart/source/detail?r=236
See if that fixes it for you.
http://forum.opencart.com/index.php/top ... ml#msg8236
http://forum.opencart.com/index.php/topic,1891.0.html
If so a solution was posted here:
http://forum.opencart.com/index.php/topic,2367.0.html
http://code.google.com/p/open-cart/source/detail?r=236
See if that fixes it for you.
-

hm2k - Global Moderator
- Posts: 583
- Joined: Tue Mar 11, 2008 1:06 am
- Location: UK
Re: Image permissions 0000
But that fix is in RC5 so it should already fix it for you.

Donate!|OpenCart Basics|GeoZones
Help me get more development cloud storage - Click Here to get DropBox
-

Qphoria - Administrator
- Posts: 18200
- Joined: Mon Jul 21, 2008 7:02 pm

Re: Image permissions 0000
Thanks for the response from both of you. I replaced this is upload.php
function save($key, $file)
{
if (file_exists($file)) @unlink($file);
$status=@move_uploaded_file($_FILES[$key]['tmp_name'], $file);
if ($status) @chmod($file, 'a+r');
return $status;
}
with this from http://forum.opencart.com/index.php/topic,1891.0.html
function save($key, $file)
{
if (file_exists($file))
{
@unlink($file);
}
$status = @move_uploaded_file($_FILES[$key]['tmp_name'], $file);
if ($status)
chmod($file, 0644);
return $status;
}
and it fixes the problem.
function save($key, $file)
{
if (file_exists($file)) @unlink($file);
$status=@move_uploaded_file($_FILES[$key]['tmp_name'], $file);
if ($status) @chmod($file, 'a+r');
return $status;
}
with this from http://forum.opencart.com/index.php/topic,1891.0.html
function save($key, $file)
{
if (file_exists($file))
{
@unlink($file);
}
$status = @move_uploaded_file($_FILES[$key]['tmp_name'], $file);
if ($status)
chmod($file, 0644);
return $status;
}
and it fixes the problem.
- djbrock
- Posts: 48
- Joined: Thu Dec 04, 2008 2:37 pm
Re: Image permissions 0000
If you didn't already have that, then it doesn't seem like you properly upgraded 0.7.8 to 0.7.9RC5

Donate!|OpenCart Basics|GeoZones
Help me get more development cloud storage - Click Here to get DropBox
-

Qphoria - Administrator
- Posts: 18200
- Joined: Mon Jul 21, 2008 7:02 pm

Re: Image permissions 0000
Unless some other contrib I've used reverted it. I actually completely deleted the directory and installed fresh from 0.7.9RC5 just last week because of such problems.
Before that I'd used WINscp to mirror the files from the \upload directory to the \store directory and then ran the upgrade.php.
Before that I'd used WINscp to mirror the files from the \upload directory to the \store directory and then ran the upgrade.php.
- djbrock
- Posts: 48
- Joined: Thu Dec 04, 2008 2:37 pm
Re: Image permissions 0000
If you could, could you change the code in the original from:
to
And try again, this should give you an error, tell me what that error is.
Meanwhile, can you also test that changing it to:
Solves the problem, without any further changes being needed...
I need you to test this as I'm not seeing this issue in my environments.
- Code: Select all
if ($status) @chmod($file, 'a+r');
to
- Code: Select all
if ($status) chmod($file, 'a+r');
And try again, this should give you an error, tell me what that error is.
Meanwhile, can you also test that changing it to:
- Code: Select all
if ($status) @chmod($file, '0644');
Solves the problem, without any further changes being needed...
I need you to test this as I'm not seeing this issue in my environments.
-

hm2k - Global Moderator
- Posts: 583
- Joined: Tue Mar 11, 2008 1:06 am
- Location: UK
Re: Image permissions 0000
I made the change to
if ($status) chmod($file, 'a+r');
but instead of an error, I got a "success" message with no icon showing.
I tried the second option
if ($status) @chmod($file, '0644');
again, a success message but no icon showing.
if ($status) chmod($file, 'a+r');
but instead of an error, I got a "success" message with no icon showing.
I tried the second option
if ($status) @chmod($file, '0644');
again, a success message but no icon showing.
- djbrock
- Posts: 48
- Joined: Thu Dec 04, 2008 2:37 pm
Re: Image permissions 0000
Are you saying that it didn't solve your problem, and there was no error?
-

hm2k - Global Moderator
- Posts: 583
- Joined: Tue Mar 11, 2008 1:06 am
- Location: UK
Re: Image permissions 0000
It did not solve the problem. In fact, it reproduced the problem. A proper upload of the image with the "success" notification, but no visible image.
- djbrock
- Posts: 48
- Joined: Thu Dec 04, 2008 2:37 pm
Re: Image permissions 0000
I really don't understand that, the only difference between the two functions you posted is the chmod...
Try this:
Try this:
- Code: Select all
if ($status) @chmod($file, 0644);
-

hm2k - Global Moderator
- Posts: 583
- Joined: Tue Mar 11, 2008 1:06 am
- Location: UK
Re: Image permissions 0000
I'm also now seeing this issue. I'm going to do some more tests later today.
-

hm2k - Global Moderator
- Posts: 583
- Joined: Tue Mar 11, 2008 1:06 am
- Location: UK
Re: Image permissions 0000
Hi hm2k,
One interesting thing I have noticed after various implementations is the user that apache runs under. Sometimes it is the same as the ftp user which makes everything easy. Other times it is not and I cannot even view or download log files.
There may be some interaction here between the folder permissions and owner (ftp user) and the apache user.
Or I may just be dreaming
One interesting thing I have noticed after various implementations is the user that apache runs under. Sometimes it is the same as the ftp user which makes everything easy. Other times it is not and I cannot even view or download log files.
There may be some interaction here between the folder permissions and owner (ftp user) and the apache user.
Or I may just be dreaming

- bruce
- Posts: 1094
- Joined: Wed Dec 12, 2007 6:26 am
Re: Image permissions 0000
Yes, it could well be a chown issue rather than chmod, or something along those lines.
However, my production server for the live site i'm testing runs suphp, so the apache/php user and ftp user should all be the same.
I will investigate it fully though a bit later on.
However, my production server for the live site i'm testing runs suphp, so the apache/php user and ftp user should all be the same.
I will investigate it fully though a bit later on.
-

hm2k - Global Moderator
- Posts: 583
- Joined: Tue Mar 11, 2008 1:06 am
- Location: UK
Re: Image permissions 0000
I've managed to recreate this problem on my own test server. I found that setting permissions to either "a+r" or "0644" is causing problems. "a+r" seems to set the permissions to "000" making the file unreadable by anyone, whereas setting permissions to "0644" is also not working properly (I'm ending up with something like "r-------T").
How I resolved the problem was by changing the following line in the save function of "library/filesystem/upload.php":-
to
Using "copy()" instead of "move_uploaded_file()" sets the permissions correctly. The temporary file created during the upload process should be deleted automatically when the script finishes executing, ie. after the file has been copied.
Fido-X.
How I resolved the problem was by changing the following line in the save function of "library/filesystem/upload.php":-
- Code: Select all
$status=@move_uploaded_file($_FILES[$key]['tmp_name'], $file);
to
- Code: Select all
$status=@copy($_FILES[$key]['tmp_name'], $file);
Using "copy()" instead of "move_uploaded_file()" sets the permissions correctly. The temporary file created during the upload process should be deleted automatically when the script finishes executing, ie. after the file has been copied.
Fido-X.

If you're not living on the edge ... you're taking up too much space!
Multi-Vendor Plugin for OpenCart 1.5.1.x
Have I helped you?
-

fido-x - Posts: 1960
- Joined: Fri Jun 27, 2008 5:09 pm
- Location: Tasmania, Australia
Re: Image permissions 0000
good work fido 
does this work regardless of a+r and 0644?

does this work regardless of a+r and 0644?

Donate!|OpenCart Basics|GeoZones
Help me get more development cloud storage - Click Here to get DropBox
-

Qphoria - Administrator
- Posts: 18200
- Joined: Mon Jul 21, 2008 7:02 pm

Re: Image permissions 0000
Qphoria wrote:does this work regardless of a+r and 0644?
Yes. You can even delete the line that reads-
- Code: Select all
if ($status) @chmod($file, 'a+r');
since "copy()" sets the permissions correctly.
PS
I have mentioned this elsewhere on the forum (http://forum.opencart.com/index.php/topic,1891.msg12007.html#msg12007), but hm2k decided to stick with "move_uploaded_file()" (not criticism - just observation, after all, using "move_uploaded_file()" should have worked).
Last edited by fido-x on Tue Dec 23, 2008 3:36 am, edited 1 time in total.

If you're not living on the edge ... you're taking up too much space!
Multi-Vendor Plugin for OpenCart 1.5.1.x
Have I helped you?
-

fido-x - Posts: 1960
- Joined: Fri Jun 27, 2008 5:09 pm
- Location: Tasmania, Australia
Re: Image permissions 0000
The option before was to use move_uploaded_file() && chmod() or copy() && unlink().
I decided to use move_uploaded_file() because its more related to what we're actually trying to do.
However, if we can't use chmod() in all situations, then we can't give the file read permissions, meaning that copy() && unlink() is our only option.
I will update the code accordingly.
I decided to use move_uploaded_file() because its more related to what we're actually trying to do.
However, if we can't use chmod() in all situations, then we can't give the file read permissions, meaning that copy() && unlink() is our only option.
I will update the code accordingly.
-

hm2k - Global Moderator
- Posts: 583
- Joined: Tue Mar 11, 2008 1:06 am
- Location: UK
Re: Image permissions 0000
Does anyone have any issues with this?
- Code: Select all
function save($key, $file) {
if (file_exists($file)) @unlink($file);
$status=@copy($_FILES[$key]['tmp_name'], $file);
if ($status) @unlink($_FILES[$key]['tmp_name']);
return $status;
}
-

hm2k - Global Moderator
- Posts: 583
- Joined: Tue Mar 11, 2008 1:06 am
- Location: UK
Re: Image permissions 0000
Only one... very small one 
Firstly, from the php manual...
so the unlink is redundant, but conservative and there is certainly no harm in that.
If we are playing conservatively, I would suggest that you also leave in the original chmod with the numeric parameter so...
cheers
Bruce

Firstly, from the php manual...
The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.
so the unlink is redundant, but conservative and there is certainly no harm in that.
If we are playing conservatively, I would suggest that you also leave in the original chmod with the numeric parameter so...
- Code: Select all
function save($key, $file)
{
if (file_exists($file))
{
@unlink($file);
}
$status = @copy($_FILES[$key]['tmp_name'], $file);
if ($status)
{
@chmod($file, 0644);
@unlink($_FILES[$key]['tmp_name']);
}
return $status;
}
cheers
Bruce
- bruce
- Posts: 1094
- Joined: Wed Dec 12, 2007 6:26 am
24 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 0 guests













