I have a problem with uploading file with PHP. The html code is
<form enctype="multipart/form-data" id="form" action="action.php">
<input type="file" name="file"/><br/><br/>
<input type="submit" id="upload" value="Upload"/>
</form>
and the PHP segment is
if($_FILES["file"]["error"]>0){
$result['status'] = -1;
$result['message'] = 'Unknown Error';
}
else{
$file = $_FILES["file"];
$savepath = '/CSV Files/'.$file["name"];
move_uploaded_file($file['tmp_name'],$savepath);
}
The problem is the $result['status'] is not -1, but the $file is a null. And the strange thing is, the code worked well days ago, and suddenly died recently.Hope somebody could help me out. Thanks a lot!
print_r($_FILES);$savepath = '/CSV Files/'.$file["name"];which may not work. If running your code from the root, change it to$savepath = 'CSV Files/'.$file["name"];without the leading/while making sure the folder has write permissions set. You should also consider not using a space betweenCSVandFilesbut using an underscore. @CharlesDou