druzuz321103 2013-08-28 22:47 采纳率: 100%
浏览 25
已采纳

通过PHP上传表单文件

(beginner)

I'm having trouble uploading my file. I see the filename being posted to the database, but the file is not being posted to the images folder. It seems as though nothing is happening. Here is my following code, please advise me what I need to change:

<?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>
  • 写回答

2条回答 默认 最新

  • dongshou7903 2013-08-28 23:11
    关注

    Here's the format for move_uploaded_file():

    $path = 'images/';
    move_uploaded_file($_FILES['art']['tmp_name'], $path.basename($_FILES['art']['name']));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?