douzhengnao8265 2010-02-08 22:29
浏览 24
已采纳

PHP文件上传,文件不会移动到本地目录

I have a problem when moving an uploaded file into a local directory.

When running the following code, the output is always "error uploading file". It seems to always not meet the condition for the 'move_uploaded_media' function and therefore $result is not being set?

Are there any glaring mistakes?

<?php

$page_title = 'Admin | Multimedia Portfolio';

include('includes/admin_header.html');

if(isset($_POST['submitted']))
{
    $uploadDir = 'files/';

    $fileName = $_FILES['userfile']['name'];
    $tmpName = $_FILES['userfile']['tmp_name'];
    $fileSize = $_FILES['userfile']['size'];
    $fileType = $_FILES['userfile']['type'];

    $filePath = $uploadDir . $fileName;

    $result = move_uploaded_file($tmpName, $filePath);
    if (!$result) {
        echo "Error uploading file"; // Here is were the it always gets caught
        exit;
    }

    require_once('mysql_connect.php');

    if(!get_magic_quotes_gpc())
    {
        $fileName = addslashes($fileName);
        $filePath = addslashes($filePath);
    }

    $query = "INSERT INTO files (name, size, type, path ) VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')";

    mysqli_query($dbc, $query) or die('Error, query failed : ' . mysql_error());

    mysqli_close($dbc);

    echo "<br>Files uploaded<br>";

    }

?>

<div id="content-wrap">

<h1>Upload Media</h1>

<div id="content">

    <form method="post" action="upload.php" encytype="multipart/form-data">

    <fieldset>

        <div class="entry">

                <label>Which media <span class="highlight">file</span> would you like to upload?</label>
                <input type="file" name="userfile" id="userfile" size="30" />

            </div>

                <fieldset id="button">
                <input type="submit" value="Register" />
                <input type="hidden" name="submitted" value="TRUE" />
            </fieldset>

        </fieldset>

    </form>

</div>

</div>

<?php

include('includes/admin_footer.html');

?>
  • 写回答

2条回答 默认 最新

  • douxiapi4381 2010-02-08 22:30
    关注

    Not sure if there is more, but you have encytype instead of enctype in your <form>.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度