dongzhan8001 2011-11-27 09:33 采纳率: 0%
浏览 52
已采纳

在WordPress下上传文件失败

I'm using WordPress and I'm following W3's guide for uploading a file:

HTML code:

<html>
<body>

<form action="upload_file.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>  

PHP code (upload_file.php):

<?php
if ($_FILES["file"]["error"] > 0)
{
  echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
  echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  echo "Type: " . $_FILES["file"]["type"] . "<br />";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
 }
?> 

The HTML code is pasted in a PHP page template and the PHP file under the WP installation directory under www.

The problem is when I submit the file I get Error: 1.
If I remark the "if" part of the PHP code and leave the "else" part I get:

Upload: IMG_4258.JPG
Type:
Size: 0 Kb
Stored in: 

So at least I know the PHP code is running.
But what's causing it to fail?
Is there a problem with the code or is WordPress meddling with the process?

  • 写回答

2条回答 默认 最新

  • douzhuo6270 2011-11-27 09:47
    关注

    If you go to the PHP manual page, instead of W3schools (sometimes not really a good resources), you would see that your error code 1 is:

    UPLOAD_ERR_INI_SIZE

    Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
    

    That means your INI directive restricts your file upload (by default it should be 2Mbyte)

    I know your is just a stub, but I suggest you doing chekcs on the kind of uploaded files, but especially actually DO UPLOAD the file (not just having it stored and then destroyed in the temporary directory) by using move_uploaded_file()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线