I'm want to chmod two files to 0777 overwirte the files with new data then chmod the files back to 0644 to secure them.

I'm reading that the directory that the files sit in needs to be chmoded to 0777 first before I can do the files and this needs to be done using ftp.

Can somebody tell me the best way to do this.

Thanks,
Peter

    most ftp cliets will let you select a dir\file and alter its permissions

      I know how to use ftp to change the permissions of files and folders but I need to be able to make the chmod changes in PHP so that I don't leave the files with r/w access to everyone with access to the website.

      I want the files write protected until I need to write updated data to the file - remove the write protection, write the new data - apply the write protection again.

      thanks,
      Peter

        Note that PHP web applications are typically run under a web server user account, not your personal login account. Therefore it is likely that your PHP script will only be able to chmod() a file if the file (or directory) was created by your script (or another PHP script), as files can only be chmod-ed by the file owner or a super-user (root) account.

          I've managed to get the CHMOD working with the code posted below. This php web page incorporates an online wysisyg web page editor which allows the the user, through a password protected folder, to update an availability chart.

          The form that displays the webpage to be edited has SAVE and BACKUP buttons which write the amended page to the live webpage which is displayed to any person accessing the availability chart from the website.

          The following code sits at the top of the php file above the html code that displays the online editor.

          One thing I got stuck on for a while was the different directory paths that are required for the ftp_site and the fopen. It may not be the best piece of coding but it does what I want in terms of protecting the files from unauthorised access.

          If ($_POST['btn_name'] == "Backup") 	
          	$file = "/home/vps_username_name/public_html/availability_chart.bak";		
          
          $ftpstream = @ftp_connect('localhost');
          //Login to the FTP server
          $login = @ftp_login($ftpstream, 'ftp_username', 'ftp_password');
          if($login) {
          		ftp_site($ftpstream, "CHMOD 0777  /public_html/availability_chart.bak");
          		$handle = fopen($file,'w');
          		fwrite($handle,$sContent);	
          		ftp_site($ftpstream, "CHMOD 0644  /public_html/availability_chart.bak");
          	    ftp_close($ftpstream);
          	}
            Write a Reply...