retoto Posted October 14, 2007 Share Posted October 14, 2007 Hi nice ppl i try to delete file with php with that code <?php $file = "test.txt"; if (unlink($file)) { echo ("Deleted $file"); } else { echo ("cant Deleted $file"); } ?> i give CHMOD 777 and still that dont delete the file :\ some one know why :\ ?? Quote Link to comment https://forums.phpfreaks.com/topic/73192-unlink-file/ Share on other sites More sharing options...
MadTechie Posted October 14, 2007 Share Posted October 14, 2007 weird.. try this see what happens *untested <?php if (file_exists($file)) { if(chmod ($file, 0777)) { if (unlink($file)) { echo "Deleted $file"; } else { echo "cant Deleted $file"; } }else{ echo "Can't change rights"; } }else{ echo "No file exists"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73192-unlink-file/#findComment-369193 Share on other sites More sharing options...
retoto Posted October 14, 2007 Author Share Posted October 14, 2007 thanks for the help man but still " Warning: chmod() [function.chmod]: Operation not permitted in /home/***/domains/***t/public_html/index.php on line 5 Can't change rights " Quote Link to comment https://forums.phpfreaks.com/topic/73192-unlink-file/#findComment-369211 Share on other sites More sharing options...
MadTechie Posted October 14, 2007 Share Posted October 14, 2007 Okay.. you may need to change the access right of the public_html, do you know what they are set to ? or the server may have some restrictions.. i guess you could try via FTP.... <?php $file = "test.txt"; $ftpUserName = 'username'; $ftpUserPass = 'userpass'; $ftpServer = 'ftp.example.com'; $ftpConn = ftp_connect($ftpServer); if (!$ftpConn) { die("Unable to connect to $ftpServer"); } if (@ftp_login($conn_id, $ftpUserName, $ftpUserPass)) { echo "Connected as $ftpUserName @ $ftpServer"; } else { echo "Couldn't connect as $ftpUserName"; ftp_close($ftpConn); die("Closed connection to $ftpServer"); } echo ftp_chmod($ftpConn, 0777, $file) ? "CHMOD successful!" : 'Error'; // try to delete $file if (ftp_delete($ftpConn, $file)) { echo "$file deleted successful\n"; } else { echo "could not delete $file\n"; } // Close the connection ftp_close($conn_id); ?> Quote Link to comment https://forums.phpfreaks.com/topic/73192-unlink-file/#findComment-369218 Share on other sites More sharing options...
retoto Posted October 15, 2007 Author Share Posted October 15, 2007 nice man thanks but i try to use Unlink anyaway thanks bro (: Quote Link to comment https://forums.phpfreaks.com/topic/73192-unlink-file/#findComment-369782 Share on other sites More sharing options...
MadTechie Posted October 15, 2007 Share Posted October 15, 2007 Okay.. you may need to change the access right of the public_html, do you know what they are set to ? Quote Link to comment https://forums.phpfreaks.com/topic/73192-unlink-file/#findComment-369866 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.