I encountered some problems when I tried to upload files using php.

Source: Internet
Author: User
When I tried to upload files using php, I encountered some problems. according to the online example, phpcode should be okay: PHPcode & lt; formenctype = & quot; multipart/form-data & quot; action = & quot; demo2.php tries to upload files using php and encounters some problems
The php code written based on the online example should be okay:
PHP code
  

PHP code
  
  

The output is
Array ([userfile] => Array ([name] => unnamed .jpg [type] => image/pjpeg [tmp_name] =>/tmp/phpdruvC1 [error] => 0 [size] => 1059 )) warning: move_uploaded_file (uploads/unnamed .jpg): failed to open stream: Permission denied in/disks/diskh/zco/maql2/public_html/test/demo2.php on line 8 Call Stack: 0.0001 329800 1. {main} ()/disks/diskh/zco/maql2/public_html/test/demo2.php: 0 0.0001 329888 2. move_uploaded_file ()/disks/diskh/zco/maql2/public_html/test/demo2.php: 8 Warning: move_uploaded_file (): unable to move '/tmp/phpdruvC1' to 'uploads/unnamed .jpg 'in/disks/diskh/zco/maql2/public_html/test/demo2.php on line 8 Call Stack: 0.0001 329800 1. {main} ()/disks/diskh/zco/maql2/public_html/test/demo2.php: 0 0.0001 329888 2. move_uploaded_file ()/disks/diskh/zco/maql2/public_html/test/demo2.php: 8

Obviously, move_uploaded_file cannot move an image or open a stream?

Because the school uses WinSCP, files are stored on the school server.
I think this is the reason why uploading is not possible. Does anyone know how to solve this problem?

------ Solution --------------------
Have you checked the file permissions,
------ Solution --------------------
View the file path
------ Solution --------------------
/Disks/diskh/zco/maql2/public_html/test/uploads directory does not exist or cannot be written
The file system does not support Chinese names
------ Solution --------------------
Permission denied in

You do not have the access permission or write permission, and may not even have the access location.
------ Solution --------------------
Warning: move_uploaded_file (uploads/test1.jpg): failed to open stream:


Check the path and determine whether the directory is writable and exists. This function will not help you create a directory.

If the file is included and executed, we recommend that you use an absolute path.
------ Solution --------------------
Now that you have uploaded the image information, you have encountered a problem. First, you need to check whether all directories exist. move_uploaded_file () cannot create a directory. second, check whether the upload path is correct. third, check whether your file has sufficient permissions. In addition, they are not the same server, and so on.
------ Solution --------------------
File path problems
------ Solution --------------------
File path problems
------ Solution --------------------

$ Folder = $ _ SERVER ["DOCUMENT_ROOT"]. "/uploads/"; // you must have an uploads folder under the root directory of your site.
Chmod ($ folder, 0777 );

If (is_uploaded_file ($ _ FILES ['userfile'] ['tmp _ name']) {

Move_uploaded_file ($ _ FILES ['userfile'] ['tmp _ name'], $ folder. $ _ FILES ['userfile'] ['name']);
} Else {
Echo 'cannot find file ';
}

?>
------ Solution --------------------
Enable all the error messages.

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.