PDA

View Full Version : how to chmod uploaded files?


Mindstorm
03-15-2004, 11:01 PM
Hello,

It's my first post here, and though I read the rules, I'm sorry if I break any that I don't know of.

I'm using a script on my website to allow some users to upload files without FTP access. The only problem is that it upload files with 0600 permissions, which makes them unreadable to global users.

I'd like to alter the script to chmod the files on upload, but my knowledge of php is (very) close to none.


$replaces = Array(
'%fullname' => $_POST['targetdir'] . '/' . $thisfile['name'],
'%filename' => $thisfile['name'],
'%dir' => $_POST['targetdir']
);

$commandline =
strtr(
$GLOBALS['default']['UPLOAD_APPLICATIONS'][ $_POST[ 'app' . $i ] ] ['commandline'],
$replaces
);

if ( !eregi( '^.*WIN.*$', PHP_OS ) )
$commandline = escapeshellcmd( $commandline );

if ( !chdir( $_POST['targetdir'] ) )
$failed = 2;
else {
exec( $commandline, $output );

$message .=
'<LI>' .
$commandline . '<BR>' . NL .
'<TEXTAREA COLS=80 ROWS=4>' .
implode( NL, $output ) .
'</TEXTAREA><BR>';

if ( isset( $_POST[ 'drop' . $i ] ) && ( $_POST[ 'drop' . $i ] == 'on' ) ) {
if (!unlink( $_POST['targetdir'] . '/' . $thisfile['name'] ))
$failed = 3;
}


(Sorry for the long code, but I'm not quite sure what matters. I've attached the complete file in case I'm missing something..)

I've read through the PHP documentation and "learnt" about the chmod function, but while I know I must use "chmod( $string , 0674 )", I'm not sure how to get the $string.

Can somebody help me with this?

Thanks in advance
Jorge Soares

PS: The script is not mine, it's https://sourceforge.net/projects/fsguide/ from trajic. It is GLPed, and I hope I'm not breaking the license by posting this here.

Nightfire
03-16-2004, 12:29 AM
Just assign $string to the filename and extension

Mindstorm
03-16-2004, 07:46 AM
Ok. but how and where do I do it?

I figure it must have something to do with "$_POST['targetdir'] . '/' . $thisfile['name'],", but as I said, my knowledge of php is nonexistent.

Regards
Mindstorm

firepages
03-16-2004, 08:17 AM
I hate code without all the braces ... grrrr


<? //......//
if (
!move_uploaded_file(
$thisfile['tmp_name'],
$_POST['targetdir'] . '/' . $thisfile['name']
)
)
$failed = 1;
else {
chmod( $_POST['targetdir'] . '/' . $thisfile['name'] , 0674 );
?>


might be close , thats the format anyway , see http://www.php.net/chmod for more info

Mindstorm
03-16-2004, 07:14 PM
Thank you, it's working fine.

I really apreciate your help, thanks

Regards
Mindstorm