(初级)
我无法上传文件。我看到文件名被发布到数据库,但文件没有发布到images文件夹。似乎没有任何事情发生。以下是我的以下代码,请告诉我需要更改的内容:
<?php
//the $art variable gets posted to a database eventually
$art = mysql_real_escape_string(stripslashes($_FILES["art"]["name"]));
$art_ext = pathinfo($art, PATHINFO_EXTENSION);
$art = md5($art).".".$art_ext;
if($art!=""){
move_uploaded_file($art, "images/".$art );
}
?>
<script type="text/javascript">
$(function(){
image_upload = {
UpdatePreview: function(obj){
// if IE < 10 doesn't support FileReader
if(!window.FileReader){
// don't know how to proceed to assign src to image tag
} else {
var reader = new FileReader();
var target = null;
reader.onload = function(e) {
target = e.target || e.srcElement;
$("#imageupload").attr("src", target.result);
};
reader.readAsDataURL(obj.files[0]);
}
}
};
});
</script>
<form action="new.php" method="post" enctype="multipart/form-data">
<input type='file' name='art' id="file" onchange='image_upload.UpdatePreview(this)' value="Upload" accept="image/gif,image/jpeg,image/png"/>
</p>
<p>upload a image! (.gif, .jpg, .png formats allowed. 5MB max)</p>
<img id="imageupload" src="1x1.png" alt="test" />
<input type="submit" class="smallbtn4" style="cursor:pointer;" value="post"/>
</form>
答案 0 :(得分:1)
使用 move_uploaded_files()时,您的目标路径还应包含文件名称 ....现在您的目标路径为:
images/
它应该是:
images/nameOfImg.ext
希望这有帮助!
编辑:
在看到@enhzflep的评论之后,你还应该在文件名中哈希,并在move_uploaded_file()中使用它之前创建你的文件名字符串;
答案 1 :(得分:1)
以下是move_uploaded_file()
的格式:
$path = 'images/';
move_uploaded_file($_FILES['art']['tmp_name'], $path.basename($_FILES['art']['name']));