IFS File Permissions When Uploading a File via PHP

470 pts.
Tags:
iSeries
PHP
Zend
Hello All, I've written a php script that uploads a file to the IFS using the following function:
move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)
It successfully uploads the file.  But, does not inherit the permissions of the folder it is contained under. I tried setting the upload_tmp_dir to a special folder with the permissions set. This didn't help at all... Any ideas? I'm using Zend on the iSeries V5R4M0

Software/Hardware used:
Zend, iSeries, V5R4MO

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hi,

try setting chmod after using move_uploaded_file
for example :
<pre><?php
chmod(“/somedir/somefile”, 0604);
?> </pre>

The above of course requires php.ini to be configured to allow chmod scripting functions. If you are unfamiliar with chomd functions you can refer to <a href=”http://us3.php.net/chmod”></a>.

If direct CHMOD is not available on your server, a worked around is by using FTP CHMOD (will result in some delay).

Example:
<pre>$target_path = “upd_img/”;
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
$filename = trim($_FILES['uploadedfile']['name']);
$ftp_server = “myftpserveraddress”;
$ftp_user_name = “ftpuser”;
$ftp_user_pass = “ftppass”;

$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if ((!$conn_id) || (!$login_result))
{
echo “FTP connection has failed!”;
echo “Attempted to connect to $ftp_server for user $ftp_user_name”;
exit;
}
echo ftp_chmod($conn_id, 0604, “upd_img/”.$filename) ? “CHMOD successful!” : ‘Error’;
ftp_close($conn_id);
echo(“Successful!”);
}
else
{
echo(“Failed!”);
} </pre>

hope the above will help

Discuss This Question: 4  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • pdraebel
    What are the permissions on the resulting file ?
    2,615 pointsBadges:
    report
  • DanD
    Tom Liotta...I'm waiting on your reply for this one. I saw you have an article I can get by paying for joining the experts site. I know you could set up a scheduler job to set authorities to a file by path and name but if you're date stamping or numbering many incoming files I don't think this would work without some pretty complicated code and the data might be temporarily unavailabe for other users.
    2,865 pointsBadges:
    report
  • TomLiotta
    I'll add a comment, though I can't say a whole lot about what's happening. Note that PHP is a 3rd-party facility with behavior of its own. It's not technically under any strict obligation to follow how any particular OS does things. With that said, you might want to review the thread that this comment by Florian resides within. Perhaps it will provide something useful. I would make sure that both Zend and IBM heard complaints about it. Tom
    125,585 pointsBadges:
    report
  • Dcantwell
    Well it looks like the file was getting full permissions for the user who uploaded it and none of the other permissions of the folder. We have certain permissions we want applied to all files in the folder. We created a Windows .bat script to compensate for it right now. The .bat script successfully applies the permissions using xcopy. That script will work for now. We were just trying to do it more interactively.
    470 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following