Questions about Move_uploaded_file () error

Source: Internet
Author: User

The Move_upload0ed_file () function returns fewer parameters, but there are many reasons for the error, so it is difficult for beginners to encounter problems.

The cause of the error is about three points:

1. If the detected file is not from post upload, this file will not perform CP work;

2. The destination path cannot be found;

3. Destination path permission non-execution process lesson read and write (this is I found in the afternoon);

First look at these lines of code to understand the environment:

if (Move_uploaded_file ($fileInfo [' Tmp_name '], $destination))

{
$mes = "File upload succeeded";
}

Else

{

$mes = "File move Failed";
}


Result returned file move failed


This afternoon to find a lot of information, probably the following several statements:

1. Should use absolute path, my parameter $destination value is uploads, plus absolute path is/home/llawlite/imooc/shopimoc/test/uploads

Verification is not the problem.

2. The path should be preceded by ROOT, $destination =root. $destination; Verified invalid;

Finally, you can only explore it yourself and find that this is a Linux file permissions issue.

First, the files that are post in the script are placed in the Temp directory (tmp_dir) and then copied to the destination path.

If the destination path does not have permission to write the file, then the function executes with an error.



This afternoon did the following attempt, first change the destination path to/tmp $destination = "/tmp". $fileInfo [' name '], the result function executes successfully.

The comparison found that the permissions of/TMP is DRWXRWXRWX, and my/home permission is drwxr-xr-x, the problem at a glance.


The following changes the permissions of/home Chmod-r 777/home (permissions are changed for all files in the entire directory and subdirectories).


Then the path is changed to the original path, the verification problem has been resolved.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Questions about Move_uploaded_file () error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.