PHP文件上传不起作用

时间:2014-02-22 03:52:11

标签: php

我正在尝试上传图片,但它总是向我显示错误。我想我已经完成了上传图片所需的一切。任何帮助将不胜感激。

HTML:

<form action="../Code Files/User.php" method="post" enctype="multipart/form-data">

    <div id="photo_settings2" style="margin-left:74px;">
        <img id="Picture" src="../../img/User No-Frame.png"/>       
    </div>

    <br><br><br><br>

    <div id='Upload_Panel' style="margin-left: 32px;">
        <input name='file' type='file' id='file_browse' onchange="readURL(this,'Picture')" style="cursor: pointer;"/>
    </div>

    <div id="delete" style="margin-top: -40px; margin-left: 198px; cursor: pointer">
        <img src="../../img/Delete_Panel.png">
    </div>

    <div style="margin-left:144px; margin-top:-15px"></div>

    <br><br> 
    </div>

    </div>

</form>

php代码:

$UploadDirectory    = '/www/';

if(move_uploaded_file($_FILES['file']['file'], $UploadDirectory))
{
    die('Success! File Uploaded.');
}

else
{
    die('error uploading File!');
}

2 个答案:

答案 0 :(得分:0)

这应该有效:

if(move_uploaded_file($_FILES['file']['tmp_name'], basename($_FILES['file']['name'])))
{
    die('Success! File Uploaded.');
}
else
{
    die('error uploading File!');
}

编辑:我已更改目标参数 - 现在上传的文件将出现在您的php文件旁边。记住目标文件夹权限。

答案 1 :(得分:0)

工作代码:

  $UploadDirectory = '/wamp/www/img/Users/Users/'.basename($_FILES['file']['name']);
  if(move_uploaded_file($_FILES['file']['tmp_name'], $UploadDirectory))
  {
      die('Success! File Uploaded.');
  }

  else
  {
      die('error uploading File!');
  }