PHP $ _ FILES: upload FILES normally in Windows, but FILES cannot be uploaded in Ubuntu

Source: Internet
Author: User
PHP $ _ FILES: upload FILES normally in Windows, but FILES cannot be uploaded in Ubuntu The following source code can be used to upload files normally in Windows Apache, but no error is reported in Ubuntu Linux, but the file cannot be uploaded to the specified directory.
How can this problem be solved.
Thank you!



$ ErrorMessage = null;
$ Message = null;
If (! Empty ($ _ FILES ['filefield'] ['name']) {
If ($ _ FILES ['filefield'] ['error']> 0 ){
$ ErrorMessage = 'Error: '. $ _ FILES ['field'] ['error'];
} Else {

If (is_uploaded_file ($ _ FILES ['filefield'] ['tmp _ name']) {
// Transfer the file
Move_uploaded_file ($ _ FILES ['filefield'] ['tmp _ name'],
'/Var/www'. '/'. $ _ FILES ['filefield'] ['name']);

$ Message = 'upload successful! ';
} Else {
$ ErrorMessage = 'Error: '.' Upload failed! ';
}
}

}
?>


Reply to discussion (solution)

It is probably a permission issue. change the upload directory to 777 and test it.

Windows is a single-user operating system and rarely encounters permission issues. Even on the server, there are very few permissions problems due to the powerful Microsoft team.
Linux is a multi-user operating system (even if you are the only one), so permission issues are everywhere. Open-source projects have not yet had weak technical support, and there have been no simple and quick tools

Move_uploaded_file determines whether the file is uploaded. is_uploaded_file is used for multiple times.
Move_uploaded_file returns an error when the directory does not exist, cannot be written, or has insufficient space.
Without discrimination, $ Message = 'upload successful! '; Is not appropriate

In the program most? Add
Ini_set ('display _ errors ', 'on ');
Error_reporting (E_ALL );

? What does it mean ?? Is it a file ?? Limit ??

In linux? Command
? Set file ?? Use? Is www-data
Chgrp www-data folder

Then? Set ?? Limited
Chmod g + rw folder

Open the error prompt.

'/Var/www'. '/'. $ _ FILES ['filefield'] ['name']
Paste directory file permissions

Thank you! this is indeed a permission issue. it will be done after modification.
Thank you.

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.