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.