Products
Services
Contact Us

Scripts: Php :: File upload operations >> Library Article #9

Developer's Section

Use an FTP connection to create directories and change permissions in PHP
By: Erobo Team Member

Hire a Developer for Related Work / Installation | $55 hr
Rating:  | Rate It:   
Average Votes: (1776)
Favorites:

Learn to connect to a server, create directories dynamically, and change the permissions on the directory using an FTP connection in PHP.

An FTP connection in PHP can be used to manage files and directories in your server. For example, you can use the following methods to create a directory and change the permissions on it:

  • Create a new connection using ftp_login() method
  • Use ftp_mkdir() to create the directory.
  • Use ftp_site() to change permissions on the directory


Example Code:

 Code Snippet 1

$ftp_server="11.101.11.10"; //your server address here 
$ftp_user_name = "ftpusername"; 
$ftp_user_pass = "ftppassword"; 
$conn_id = ftp_connect($ftp_server);  
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

if($login_result) {
  echo "You are now Connected";
  ftp_cdup($conn_id); //go to your parent directory
  ftp_chdir($conn_id,"web"); //then go to web directory
  ftp_chdir($conn_id,"documents"); //then go to documents
  ftp_mkdir($conn_id, "user5"); //create user5 in directory location: 
                                              //root/web/documents/
                                              //Thus new location is:
                                              //root/web/documents/user5
  //change the file permissions on the new folder
  ftp_site($conn_id,"CHMOD 0777 " . "user5");
  ftp_close($conn_id); //close the connection
}
else {
  echo "Unable to connect";
}


See other Scripts in File upload operations

Submit Your Scripts:


System Message:
  • Your PHP script has been sent. Please allow 48 hours for processing.


If you would like to have your PHP scripts published in this section please fill out
the form below:
*Your Name or Username:
Home Town:
*Email:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]