duanke1984 2018-11-20 16:40
浏览 43

PHP无法移动上传的文件

I use this form to upload an image to my PHP:

<form method="post" action="http://my.domain/media.php" enctype="multipart/form-data">
    <input type="hidden" name="MAX_FILE_SIZE" value="10485760" />
    <input type="file" name="mediafile"></input>
    <input type="submit"></input>
</form>

And I use this PHP code to retrieve the uploaded file (image):

$mfn = "./upload_test.png";
if (move_uploaded_file($_FILES['mediafile']['tmp_name'], $mfn)) {
    if (file_exists($mfn)) {
        echo 'success';
    } else {
        echo 'Uploaded file didn\'t move to the requested path.';
        print_r($_FILES);
    }
} else {
    echo 'move_uploaded_file error<br/>';
    print_r(error_get_last());
    echo '<br/>';
    print_r($_FILES);
}

When I click the submit button, the move_uploaded_file returns an error. So, I caught debug data with print_r(error_get_last()):

Array (
[type] => 2
[message] => move_uploaded_file(): open_basedir restriction in effect. File() is not within the allowed path(s): (/home/username/:/tmp:/var/tmp:/usr/local/lib/php/)
[file] => /home/username/domains/my.domain/public_html/media.php
[line] => 96 )

and with print_r($_FILES):

Array (
[mediafile] => Array (
    [name] => test.png
    [type] => image/png
    [tmp_name] => /tmp/phpvoQr3i
    [error] => 0
    [size] => 38207 )
)

NOTE: I can't edit php.ini or any admin settings.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端