Reputation: 117
I'm trying to upload files through the PHP function move_uploaded_file and this is what I have so far:
if (move_uploaded_file($file["tmp_name"], iconv("UTF-8","big5",$target_file))) {
return true;
}
else {
echo "Not uploaded because of error #".$file["error"];
exit(0);
return false;
}
As for $target_file
, it is the location I'd like to upload my files, which is currently stu_feedback/105502504/feedback_20180910.pdf.
Yet, the files are all failed to be uploaded, which obviously goes to the else part.
But when I wanted to echo the error message, it only shows 0.
I use Filezilla Client. I have tested on my localhost and it could upload files correctly. Does anyone know what actually happened?
Upvotes: 0
Views: 104
Reputation: 799
I see some problems on this part :
enctype
to the form <form enctype="multipart/form-data">
;Be sure that the folder where you want to move files are permissions (chmod -R /folder_name 777)
Try to put in a try catch you code something like :
try{
if (move_uploaded_file($file["tmp_name"], iconv("UTF- 8","big5",$target_file))) {
return true;
}
else {
echo "Not uploaded because of error #".$file["error"];
//exit(0);
return false;
}
}catch (\Exception $e){
var_dump($e->getMessage());
die();
}
Upvotes: 1