raduenea Posted February 8, 2009 Share Posted February 8, 2009 Hy I have a script to upload a file on server. The folder where the file is on server have chmod=0755. So a made a class ftp to make the folder 777, upload the file and then to change to 755. here is the class: class ftp{ var $conect; var $poze_mici; var $poze_mari; function conFTP() { // Set up variables $host = 'ftp.xxx.com'; // host (website) that contains the folder you want to change $user = 'username'; // username to log onto the host $password = password; // password to log onto the host $pix_lit = 'public_html/reviste/pix_lit/'; $pix_big = 'public_html/reviste/pix_big/'; // folder name to change //$mod = '0777'; // permissions to be set // connect to FTP site $conn = ftp_connect("$host"); if (!$conn) { echo 'Error: Could not connect to ftp server'; exit; } // log in to FTP site @ $result = ftp_login($conn, $user, $password); if (!$result) { echo "Error: Could not log on as $user"; ftp_quit($conn); exit; } $this->conect = $conn; $this->poze_mici = $pix_lit; $this->poze_mari = $pix_big; } function openFTP() { ftp_site($this->conect, 'CHMOD 0777 '.$this->poze_mici); ftp_site($this->conect, 'CHMOD 0777 '.$this->poze_mari); } function closeFTP() { // close the connection ftp_site($this->conect, 'CHMOD 0755 '.$this->poze_mici); ftp_site($this->conect, 'CHMOD 0755 '.$this->poze_mari); ftp_close($this->conect); } } And here is where upload file: require("../functions.php"); $ftp = new ftp(); $ftp->conFTP(); $ftp->openFTP(); // here upload the file $ftp->closeFTP(); the openftp change to 777. But closeftp function don't change back to 755. The folde remain to 777. Any sugentions? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/144307-ftp-conection/ Share on other sites More sharing options...
Daniel0 Posted February 8, 2009 Share Posted February 8, 2009 Are you changing the working directory between calling ftp::conFTP() and ftp::closeFTP()? Also, why are you even doing this in the first place? Quote Link to comment https://forums.phpfreaks.com/topic/144307-ftp-conection/#findComment-757331 Share on other sites More sharing options...
raduenea Posted February 8, 2009 Author Share Posted February 8, 2009 With this class all I want is: before I upload a file on server on the specific folder I want to change the permission of the file to 0777 with this function $ftp->openFTP(); After the file is uploaded I want to chabged back to 0755 with this function $ftp->closeFTP(); I'm doing this because I need to change de permission of the folder to have the rights to write, and after that changed back. Quote Link to comment https://forums.phpfreaks.com/topic/144307-ftp-conection/#findComment-757635 Share on other sites More sharing options...
Daniel0 Posted February 8, 2009 Share Posted February 8, 2009 As far as I'm concerned, only the owner of a file can change its permissions, so you must be the owner of the file. However, in both 755 and 777 the owner has write permissions, so it seems redundant to me. I might be wrong though and I haven't tested it. Quote Link to comment https://forums.phpfreaks.com/topic/144307-ftp-conection/#findComment-757636 Share on other sites More sharing options...
raduenea Posted February 9, 2009 Author Share Posted February 9, 2009 I am the owner of the file. The default value of the folder on server is 0755. With this function ($ftp->openFTP() I change to 0777 and the change is make perfectly. I upload the file in that folder and it uploaded ok. Then I change back to 0755 with $ftp->closeFTP(); but it dosen't change. The folder remain with 0777. Is something wrong with the code but I don't know that is it. Quote Link to comment https://forums.phpfreaks.com/topic/144307-ftp-conection/#findComment-757949 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.