Forums / Contribution-Writing Guidelines / How does mkdir(DIR_FS_DOWNLOAD_PUBLIC . $tempdir, 0777) succeed?

How does mkdir(DIR_FS_DOWNLOAD_PUBLIC . $tempdir, 0777) succeed?

Locked

Started by zcnb on 24 Aug 2008, 7:45 PM · Views: 3,751

Results 1 to 3 of 3
This thread is locked. New replies are disabled.
24 Aug 2008, 7:45 PM
#1
zcnb avatar

zcnb

Zen Follower

Join Date:
Jun 2008
Posts:
338
Plugin Contributions:
0

How does mkdir(DIR_FS_DOWNLOAD_PUBLIC . $tempdir, 0777) succeed?

The PHP script includes/modules/pages/download/header_php.php creates a temporary subdirectory in directory pub, although pub's permissions are identical to all other Zen Cart directories (755):

drwxr-xr-x 3 zcnb zcnb 4096 Jul 24 16:24 pub

I was trying to create a temporary file in the download directory in the same manner, in that same exact includes/modules/pages/download/header_php.php file, but that operation fails. I understand that for security reasons, the script handling customer's download session should not be able to write/create a file in any directory. But the fact that Zen Cart is able to do so inside the same PHP script I am trying to modify, hints that there is a way to succeed in what I am trying to accomplish.

What is the proper way to create/copy a file (on the fly, as a result of the customer clicking the 'download' button) inside the download directory?

Thanks,
Daniel

24 Aug 2008, 9:06 PM
#2
paulm avatar

paulm

Totally Zenned

Join Date:
Nov 2003
Posts:
1,878
Plugin Contributions:
5

Re: How does mkdir(DIR_FS_DOWNLOAD_PUBLIC . $tempdir, 0777) succeed?

Do you use the umask function before trying to create the directory?

in includes/modules/pages/download/header_php.php it is being used like this:

  umask(0000);

http://docs.php.net/manual/en/function.umask.php

24 Aug 2008, 9:16 PM
#3
zcnb avatar

zcnb

Zen Follower

Join Date:
Jun 2008
Posts:
338
Plugin Contributions:
0

Re: How does mkdir(DIR_FS_DOWNLOAD_PUBLIC . $tempdir, 0777) succeed?

paulm:

Do you use the umask function before trying to create the directory?

Of course I use the umask function - although I knew up front that it wasn't going to help in my case: :smile:

$copyfile_errmsg = "Can't copy " . $origin_filename . " to " . $temp_filename;
umask(0000);
copy($origin_filename, $temp_filename) or die($copyfile_errmsg);

IMHO, the problem has to do with the PHP script running under the PHP session, which is not the same as the owner of the Zen Cart directories. This is understandable and good for security purposes.

However, what I don't understand is how that mkdir(DIR_FS_DOWNLOAD_PUBLIC . $tempdir, 0777) manages to succeed in creating that $tempdir... Are the permission rules different for creating directories vs. creating files?