简体   繁体   中英

PHP rename file to this sql id

I have the following lines of php code which should rename a file which already exists on the server to the id generated in the last query:

$image1Oldname = "images/" . $myfile;
$image1NewName = "images/" . mysql_insert_id() . ".jpg";

rename($image1Oldname, $image1NewName);

For some reason this does not rename the file when the script is run.

Any suggestions?

Any suggestions?

Sure.
You have to learn how to debug your code.

It is not a rocket science though.

  • Just turn all possible error reporting on
  • and echo out every piece of data you are using to see if something goes wrong.
ini_set('display_errors',1);
error_reporting(E_ALL);

$image1Oldname = "images/" . $myfile;
$image1NewName = "images/" . mysql_insert_id() . ".jpg";

var_dump($image1Oldname, $image1NewName);
rename($image1Oldname, $image1NewName);
exit;

您是否检查过您(您的PHP守护程序)是否有权重命名它,并且路径正确?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM