Fixed: PHP move_uploaded_file() and copy() function is not uploading the file
In the programming field we usually need to upload the files in the folders.
In PHP, we have 2 functions for the purpose.
1st is move_uploaded_file()
2nd one is copy().
I think you know well, what the difference between these two copy() vs move_uploaded_file().
Well, if you not aware about the difference between the above 2 PHP functions that is used for file uploading.
Click to view the difference between PHP copy() and PHP move_uploaded_file() function.
But this is not my prupose for wrting this post. I want to aware you that sometimes the file uploaded error is something different.
First of all whenever you upload a file you just need to check weather you have used encryption type enctype=”multipart/form-data” and have to use POST method.
GET method can’t upload file in any case.
Cool, you have used that then first of all check weather the file has been passed by form and have uploaded to the temp directory.
Basically this is the functionality of file uploading, first during the form post action file uploaded to the temp directory and then we have to move or copy that file in our desired folder or directory.
How can you check the temp directory, in which file is going to upload, you can check the same using phpinfo().
You can also change the same (default temp directory) that can be seen in the php.ini file.
If you uploaded a file, but file is not uploaded, first check whether the file ha been uploaded in temp directory or not.
If there has been some error occurred, you can check by print_r array of $_FILES variable.
$_FILES
If you get error that means files is not uploaded in temp directory.
It may have 2 reasons, whether the directory no exists or the directory hasn’t proper permission.
You can get rid by 2 solutions.
1) Change the path of temp directory in php.ini
2) Check the permission and folder existence.
I think, you will better fix the issue related to file upload.
Better Coding, Happy Coding!!