1

I've created a new folder on FTP server using PHP. Now I want to set all the permissions recursively(i.e. the same permissions should be applied to all the files and folders residing it.)

I tried to research about this thing then I came to know about the built-in PHP function ftp_chmod(). I searched for examples where this function is implemented but everywhere I'm getting examples of assigning permission to a file not to a folder. So can someone please help me in this regard please?

Following is the code I tried:

$ext = pathinfo($_FILES['student_image']['name'], PATHINFO_EXTENSION);     
$student_image_name = 'student_'.$t.'.'.$ext;
$_POST['student_name'] = $student_image_name;
$ftp_server="52.237.5.85"; 
$ftp_user_name="myservercreds"; 
$ftp_user_pass="MyServerCreds";

$file = $_FILES['student_image']['name'];//tobe uploaded 
$remote_file = "/Students/".$_POST['student_name']; 

// set up basic connection 
$conn_id = ftp_connect($ftp_server);  

// login with username and password 
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

if($login_result) {
  if(!is_dir('ftp://myservercreds:MyServerCreds@52.237.5.85/Students')) {
    ftp_mkdir($conn_id, "/Students");
    ftp_chmod($conn_id, 'all');//Here I'm getting issue in assigning all the permissions recursively to the newly created folder '/Student'
  }

Can someone please help me in this regard?

PHPLover
  • 1
  • 51
  • 158
  • 311

1 Answers1

1

ftp_chmod requires 3 arguments. The second one is to be of integer type, specifying mode. The third is the file name. So, the correct codeline would be:

//                  mode      file
ftp_chmod($conn_id, 0777, '/Students'); // access for everyone for read/write

Hope it helps.

Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
  • Thanks for your help. But I still have one query. Here I'm not assigning permissions to a file. I want to assign all the permissions(i.e. read, write, delete) recursively to the folder called "Students". So will it work and all the permissions would get apply recursively? – PHPLover Dec 03 '14 at 06:59
  • AFAIK, FTP does not support recursive operations at all. So to recursively assign the permissions you need to iterate through files there and assign permissions one by one. Sorry for that, but that’s how FTP proto works. – Aleksei Matiushkin Dec 03 '14 at 07:05