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 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分