Page 1 of 1

Subdirectories not getting chmod

Posted: Wed Oct 13, 2010 3:53 pm
by ecrs
I'm using the parameters to attempt to set all uploaded files and folders to 0777 permissions (this is necessary for our situation). The created account folder as well as each individual file has the permissions set correctly, but any uploaded subfolders do not (they are set to 0755 instead of the desired 0777). Is there a way to chmod the subfolders as well?

edit: wanted to note that I'm using ftp to upload, and other than this everything is working fine

Re: Subdirectories not getting chmod

Posted: Fri Oct 15, 2010 5:36 pm
by support
No, chmod is only for file. It's something we can add to the wish list (or implement quickly if you're willing to pay for it). You can contact support(at)jfileupload(dot)com

Re: Subdirectories not getting chmod

Posted: Tue Oct 19, 2010 4:12 pm
by ecrs
I have added this functionality myself, and included the code in hopes that it be implemented in future releases so everyone can use it.

The following parameters should be set:

<PARAM NAME="folderdepth" VALUE="-1">
<PARAM NAME="postparameters" VALUE="extrarelative"
<PARAM NAME="param9" VALUE="notifyrelativefilename">');
<PARAM NAME="value9" VALUE="true">
<PARAM NAME="post" VALUE="http://www.yoursite.com/postftp.php">

This is what is in postftp.php:

Code: Select all

<?php
//chmod of subfolders, since JFileUpload does not support this
//jason blount 10/10

$debug = false; //change this?

// FTP access parameters
$host = 'FTP.SITE.COM';
$usr = 'USER';
$pwd = 'PASS';

if(isset($_POST['filename1'])){
	 if ($debug) $log = fopen("ftpdebug.txt","a");
	 if ($debug) fwrite($log,"\n-----".date("D M j G:i:s T Y")."-----\n");
	
	 // connect to FTP server
	 $conn_id = ftp_connect($host);
	 if (ftp_login($conn_id, $usr, $pwd)){
		 if ($debug) fwrite($log, "logged onto $host\n");
	 }else{
		 if ($debug) fwrite($log, "failed to log onto $host!\n");
	 }

    //need to chmod each folder to 0777
    //$acc= $_POST['account']; //uncomment these line
    //ftp_chdir($conn_id, $acc); //if you use account param
    //if ($debug) fwrite($log, "account: $acc\n");
    foreach($_POST as $key => $file){
        if (substr($key, 0, 8) == "filename"){
            //each uploaded file
            if ($debug) fwrite($log, "$key => $file\n");
            $subs = str_replace("\\","/",$file);
            $subs = substr($subs, 0, strrpos($subs,"/"))."/";
            if ($debug) fwrite($log, "subs: $subs\n");
            while(strpos($subs, "/") !== false){
                //while there are still directories in here
                $subs = substr($subs,0,strlen($subs)-1);
                if ($debug) fwrite($log, "chmod $subs to 0777\n");
                ftp_chmod($conn_id, 0777, $subs);
                $subs = substr($subs, 0, strrpos($subs,"/")+1);
                if (strlen($subs) <= 2) $subs = "";
            }
        }
    }
	 ftp_close($conn_id); 
	 if ($debug) fclose($log);
}
?>
Edit the text in caps to suit your needs. Hope this helps :D

Re: Subdirectories not getting chmod

Posted: Tue Oct 19, 2010 9:01 pm
by support
Thanks!