drouie2014 2012-04-09 22:23
浏览 29

PHP文件上载无法工作的可能原因

Here is the HTML:

<h1>Upload Custom Logo</h1>
<form action="settings.php" enctype="multipart/form-data" method="post">
<input type="file" name="Logo" />
<input type="submit" value="Upload" name="logoUpload" />
</form>

Here is the PHP:

<?php /* Handle Logo Upload */
if($_POST['logoUpload']) {

$target_path = "uploads/";
$Logo = $_FILES['Logo']['name'];

$target_path = $target_path . basename( $_FILES['Logo']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo '<div class="statusUpdate">The file '.  basename( $_FILES['Logo']['name']). 
        ' has been uploaded</div>';
    }   

} else{
    echo '<div class="statusUpdate">There was an error uploading the file to: '.$target_path.', please try again!  Error Code was: '.$_FILES['Logo']['error'].'</div>';
}

}
?>

It always goes to the "else" statement on that code, I have an uploads folder in the same directory as this php file set to 777 file permissions. The image I am test uploading is under 10KB in size. But the move_uploaded_file() always fails and it doesn't return any error message except for the custom error message made with the else statement.

  • 写回答

2条回答 默认 最新

  • douwei8096 2012-04-09 22:27
    关注

    Possible reasons:

    • The uploading of the file failed in some way.
    • You don't have permission to move the file to the target path.

    As PHP.NET says:

    If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.

    If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.

    Reference: http://php.net/manual/en/function.move-uploaded-file.php

    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题