Subdirectories not getting chmod

Upload core product.
Post Reply
ecrs
Posts: 3
Joined: Thu Oct 07, 2010 3:10 pm

Subdirectories not getting chmod

Post 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

User avatar
support
Posts: 1503
Joined: Sun Jan 27, 2008 6:19 pm

Re: Subdirectories not getting chmod

Post 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

ecrs
Posts: 3
Joined: Thu Oct 07, 2010 3:10 pm

Re: Subdirectories not getting chmod

Post 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

User avatar
support
Posts: 1503
Joined: Sun Jan 27, 2008 6:19 pm

Re: Subdirectories not getting chmod

Post by support »

Thanks!

Post Reply