[英]File upload in PHP not working?
My file upload system just isn't working properly, it doesn't return true when I call move_uploaded_file()
. 我的文件上传系统无法正常工作,当我调用move_uploaded_file()
时,它没有返回true。 Here is my code, not sure if i'm just blind: 这是我的代码,不确定我是否只是盲目:
HTML: HTML:
<form action="updatecheat.php" method="POST">
<label for="version">Version:</label>
<input type="text" class="form-control" id="version" name="version" placeholder="New Version Number" />
<input type="hidden" name="referrer" id="referrer" value="coven-updates.php" />
<div class="custom-file-upload">
<label for="covenupdate">Upload "Coven.exe"</label>
<input type="file" id="covenupdate" name="covenupdate" />
</div>
<br /><br />
<button type="submit" name="submit" id="submit" class="btn btn-success waves-effect waves-light m-r-10">Update</button>
</form>
PHP: PHP:
$errors= array();
$file_name = $_FILES['covenupdate']['name'];
$file_size =$_FILES['covenupdate']['size'];
$file_tmp =$_FILES['covenupdate']['tmp_name'];
$file_type=$_FILES['covenupdate']['type'];
if(move_uploaded_file($file_tmp,"../Coven/Utilites/Update/".$file_name)){
$fn = "../Coven/Utilities/Version.txt";
$file = fopen($fn, "w+");
$size = filesize($fn);
fwrite($file, $_POST['version']);
$text = fread($file, $size);
fclose($file);
header("Location: urlhere");
} else {
header("Location: urlhere");
}
I have no clue why it isn't uploading properly. 我不知道为什么上传不正确。 Any help is appreciated! 任何帮助表示赞赏! Thanks! 谢谢!
With your form tag you are missing one attribute enctype='multipart/form-data' which is must while you are working with upload file. 使用表单标签时,您缺少一个属性enctype ='multipart / form-data',该属性在您处理上传文件时必不可少。
So, just change your form tag to this: 因此,只需将表单标签更改为:
<form action="updatecheat.php" method="POST" enctype='multipart/form-data'>
您需要包括enctype才能使文件ulpload正常工作。即enctype =“ multipart / form-data”
Try with add attribute enctype='multipart/form-data'
and 尝试使用添加属性enctype='multipart/form-data'
和
File will be stored in temporary location, use tmp_name
instead of name 文件将存储在临时位置,使用tmp_name
代替name
if(move_uploaded_file($file_tmp,"../Coven/Utilites/Update/".$file_name)){
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.