Hi, I'm pretty new to PHP and I am trying to rename a file using PHP code. My code looks like this: rename("/var/www/html/$old.html","/var/www/html/$random.html"); PHP: Where $old contains the name of the file and $random contains a string of numbers. When I run the code it gives me this error in my web browser: Warning: rename(/var/www/html/Array.html,/var/www/html/556055023.html) [function.rename]: No such file or directory in /var/www/html/echo.php on line 283 How would I fix this? Thanks, Keegan
There is no Array.html file. Maybe the $old is an array and the filenames is the elements of that array. If you cannot solve that problem, write here and I will try to help you.
I have been trying to have the code print out the actual file name which is stored into $old, but everything I've tried gives me that same result, where it prints out Array instead of the file name. The variable $Random works, but some how $old doesn't. I am getting $old with the code below: $old=file("/var/www/html/Rand_No.txt"); // records old html name fwrite(fopen("/var/www/html/Rand_No.txt", "w+"),$random); // records new html name over old html name fclose(fopen("/var/www/html/Rand_No.txt", "w+")); rename("/var/www/html/$old.html","/var/www/html/$random.html"); PHP: Thanks for your help, Keegan
You may try this code pls: //records old html name. -> return array $old = file("/var/www/html/Rand_No.txt"); //you'd better print_r($old);tell me what this result is? foreach($old as $key=>$value) { //$random where is $random from?? //add $random at this line pls.be sure the value of random are different!! if(rename("/var/www/html/$value.html","/var/www/html/$random.html")) { //true : be sure php script can creat a new text file for recording the true result $fp = fopen('/var/www/html/rename_true.txt','ab+'); fwrite($fp,$random); fclose($fp); }else{ //false : be sure php script can creat a new text file for recording the false result $fp = fopen('/var/www/html/rename_false.txt','ab+'); fwrite($fp,$random); fclose($fp) } } PHP: ------- Wu