Home > Backend Development > PHP Problem > How to find the cause of php rename error

How to find the cause of php rename error

藏色散人
Release: 2023-03-11 18:34:02
Original
2801 people have browsed it

How to find the cause of the php rename error: 1. Add some security checks; 2. Turn on the error report "error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);".

How to find the cause of php rename error

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to find the error in PHP:rename() reason?

I want to print out the reason for the error.

error_get_last() doesn't seem to return anything. rename() returns true false, not an exception.

if (!rename($file->filepath, $full_path)) {
  $error = error_get_last();
  watchdog('name', "Failed to move the uploaded file from %source to   %dest", array('%source' => $file->filepath, '%dest' => $full_path));
}
Copy after login

Solution

First of all, it is best to add some security checks before the following situations:

if (file_exists($old_name) && 
    ((!file_exists($new_name)) || is_writable($new_name))) {
    rename($old_name, $new_name);
}
Copy after login

Secondly, you can turn on error reporting:

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to find the cause of php rename error. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template