Crs Posted August 17, 2010 Share Posted August 17, 2010 Hi, I gave the following php script: #!/usr/bin/php -f <?php require_once(dirname(dirname(__FILE__))."/modules/common/common.config.inc.php"); $path = $conf["root"]."/media/images/tricouri/tmp/"; $command = "rm -Rf".$path."*"; if(exec($command)) { echo "Folder cleared\n"; } else { echo "Folder clear failed\n"; } ?> I want to delete some .png files from the ./tmp folder and I receive a rm error: rm: invalid option -- / Try `rm --help' for more information. Folder clear failed The rm -rf command sintax is ok on the linux bash, but from php i receive the error. Php safe mode is off. Can someone help, please ? Link to comment https://forums.phpfreaks.com/topic/210957-deleting-files/ Share on other sites More sharing options...
trq Posted August 17, 2010 Share Posted August 17, 2010 It should be -r not -R Link to comment https://forums.phpfreaks.com/topic/210957-deleting-files/#findComment-1100307 Share on other sites More sharing options...
Crs Posted August 17, 2010 Author Share Posted August 17, 2010 # rm --help -r, -R, --recursive remove directories and their contents recursively the two options are the same Link to comment https://forums.phpfreaks.com/topic/210957-deleting-files/#findComment-1100309 Share on other sites More sharing options...
bh Posted August 17, 2010 Share Posted August 17, 2010 is your $path and $command content correct? Is there a space at the beginning of the $path? $command = "rm -Rf".$path."*"; Link to comment https://forums.phpfreaks.com/topic/210957-deleting-files/#findComment-1100313 Share on other sites More sharing options...
Crs Posted August 17, 2010 Author Share Posted August 17, 2010 $command = "rm -rf".$path."*"; -no space and the $path and $command are ok Link to comment https://forums.phpfreaks.com/topic/210957-deleting-files/#findComment-1100316 Share on other sites More sharing options...
trq Posted August 17, 2010 Share Posted August 17, 2010 # rm --help -r, -R, --recursive remove directories and their contents recursively the two options are the same Weird. Ive been a Linux user for about 6 years and never knew this switch. Link to comment https://forums.phpfreaks.com/topic/210957-deleting-files/#findComment-1100319 Share on other sites More sharing options...
trq Posted August 17, 2010 Share Posted August 17, 2010 Looking at it now it seems you don't have a space between your options and your path. $command = "rm -Rf ".$path."*"; If that doesn't work, echo $command to see what you actually have. Link to comment https://forums.phpfreaks.com/topic/210957-deleting-files/#findComment-1100322 Share on other sites More sharing options...
Crs Posted August 17, 2010 Author Share Posted August 17, 2010 ok, so you were right about the space. now it seems to be ok, I get no error from the script, but the files don't get deleted. Any ideas ? Is it ok to use the unlink function ? Link to comment https://forums.phpfreaks.com/topic/210957-deleting-files/#findComment-1100341 Share on other sites More sharing options...
bh Posted August 17, 2010 Share Posted August 17, 2010 Yeah, its better than use exec function. Link to comment https://forums.phpfreaks.com/topic/210957-deleting-files/#findComment-1100351 Share on other sites More sharing options...
AtlasC1 Posted August 17, 2010 Share Posted August 17, 2010 Yeah, it's best to avoid any system calls whenever you get the chance. P.S: You probably have to set up an exception in SE Linux, if you have it installed, in order for a rm command to work. -jm Link to comment https://forums.phpfreaks.com/topic/210957-deleting-files/#findComment-1100375 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.