Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Z_ChangeStockCode.php does not rename image file
04-12-2013, 05:48 PM,
#1
Z_ChangeStockCode.php does not rename image file
Hi:

Z_ChangeStockCode.php script does not rename the image file.

In a shared hosted installation (Hostgator), the rename function fails to rename but returns true :-(

Code:
        echo '<br />' . _('Changing any image files');
        if (file_exists($_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'.jpg')) {
            if (rename($_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'.jpg',
                $_SESSION['part_pics_dir'] . '/' .$_POST['NewStockID'].'.jpg')) {
                    echo ' ... ' . _('completed');
                } else {
                    echo ' ... ' . _('failed');
                }
        }

I already checked that the files exists and it is not renamed, but the echo said "completed", so rename function returned true.

Any clue why?

Regards,
Pak Ricard
Reply
04-13-2013, 05:50 PM, (This post was last modified: 04-13-2013, 05:56 PM by PakRicard.)
#2
RE: Z_ChangeStockCode.php does not rename image file
Tim replied by email:

I am going to guess that it is not the rename that returned completed,
but that actually it is the file_exists() that is returning false, as
this returns the same completed message. Can you try changing the
message for when the file_exists() fails, and so it will help narrow
down the problem.

Is this a windows machine?

Thinking about this further, I suspect the hoster is running php <=5.3
and is running it in safe mode (safe mode is removed in >5.3). This
file_exists() check is unnecessary really as obviously the rename will
just have no affect if the file doesn't exist. I suggest you try
removing that check and seeing if it works then.
---------------------------

Thanks Tim:

Already checked it out, and the file_exists() is working fine (as it does all over webERP when looking to read the image file, as in stocks.php), I replaced the echo text and the problem relies on the rename() function, I guess.

It is a windows client machine but weberp lives in a unix server machine, so interpreted in a unix environment.

PHP version 5.2.17
MySQL version 5.5.23-55

Could it be a permissions problem? 0644 is ok?
Regards,
Pak Ricard
Reply
04-14-2013, 06:01 PM, (This post was last modified: 04-15-2013, 12:53 PM by phil.)
#3
RE: Z_ChangeStockCode.php does not rename image file
I've simplified that logic to remove the test for the file exists as suggested by Tim.
The file and part pics directory need to be writable by the web-server user www-data or nobody or whatever you unix distro uses for the web-server user
if the file/directory are owned by the web-server user then :

Code:
rwx r-x r-x


should do it ok.
Phil Daintree
webERP Admin
Logic Works Ltd
http://www.logicworks.co.nz
Reply
04-16-2013, 01:56 PM,
#4
RE: Z_ChangeStockCode.php does not rename image file
Thanks Phil: Yes, it was permissions problem.

Anyway, I do believe we still need the file_exists() check.

many thanks!
Regards,
Pak Ricard
Reply
04-16-2013, 02:03 PM,
#5
RE: Z_ChangeStockCode.php does not rename image file
Well won't the rename simply fail if the file does not exist?
Maybe I'd better put the test for file_exists() back if not!!
Phil Daintree
webERP Admin
Logic Works Ltd
http://www.logicworks.co.nz
Reply
04-19-2013, 11:55 AM,
#6
RE: Z_ChangeStockCode.php does not rename image file
Hi:

The file_exists() does fail depending on the user running the script.

On the very same machine against the very same webERP installation:
- If a regular user (not admin) runs Z_ChangeStockCode.php it says "No image to rename".
- logout and login as admin user... it works perfectly. It finds the image and renames it.
- logut and login again an a 3rd user (not admin) and fails again.

To test the issue added these 4 lines just before the if file_exists() to snif the filesnames and in both cases are OK.

Code:
        $oldfilename = $_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'.jpg';
        $newfilename = $_SESSION['part_pics_dir'] . '/' .$_POST['NewStockID'].'.jpg';
        echo ' OLDNAME ' .$oldfilename;
        echo ' NEW ' .$newfilename;

So, it has to do with some privileges needed for file_exists().

Could you pls test it?
Regards,
Pak Ricard
Reply
02-19-2014, 06:00 PM,
#7
RE: Z_ChangeStockCode.php does not rename image file
This imaging SDK enables you to save image with customized file name and file path. You can also process your image with this SDK according to own requirements. You may have a try.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)