dongshao6591 2015-09-23 15:00
浏览 151
已采纳

php文件无法上传,错误代码为0

I am trying to upload files using php to directory that is not in the same directory that the upload script is, here is the structure of dir's:

var>www>html>
            foo>index.php //this ones where upload is done
            bar>          //this is where I want to upload it

the index.php file's form element:

<form enctype="multipart/form-data" method="POST" action="index.php">
            <fieldset style='width:33%;'>
                <legend>UPLOAD PROJECT FILES</legend>
                <select name="dirList" id="dirList" onChange="getSubDir(this.value)" required>
                    <option value="">SELECT PROJECT</option>
                    <?php
                        $path = "../";
                        $scan = scandir($path);
                        foreach($scan as $result){
                            if($result === '.' or $result === '..') continue;
                            if(is_dir($path . '/' . $result)){
                                echo "<option value='../$result'>$result</option>";
                            }
                        }
                    ?>
                </select>
                <select name="subDirList" id="subDirList">
                    <option value="">SELECT PATH</option>
                </select>
                <input type="file" name="filePath"/>
                <input type="submit" name = "upload" value="UPLOAD"/>
            </fieldset>
        </form>

so the idea here is to get the list of folders from first combobox which will get me the list of subdirectories in the second combobox.

and then the php function at the head of index.php for uploading the file:

if(isset($_POST['upload'])){
            $upload_path = $_POST['subDirList'];
            if($upload_path == ''){
                $upload_path = $_POST['dirList'];
            }
            $upload_path = getcwd().'/'.$upload_path;
            $upload_path = $upload_path.'/'.basename($_FILES['filePath']['name']);              
            if(move_uploaded_file($_FILES["filePath"]["tmp_name"], $upload_path)){
                echo "success";
            } else {
                echo print_r($_FILES);
                echo 'fail';
            }

        }

the error log:

[Wed Sep 23 14:10:46.841250 2015] [:error] [pid 4028] [client 78.167.168.253:52438] PHP Warning:  move_uploaded_file(): Unable to move '/tmp/phpEB1a3s' to '/var/www/html/eShop/Capture.PNG' in /var/www/html/ftp/index.php on line 16, referer: http://xxx.xx.xx.xx/ftp/index.php
  • 写回答

1条回答 默认 最新

  • donjd86266 2015-09-24 11:26
    关注

    Check if you have writte permissions.

    Then, by documentation also check if the file name is valid, and remeber the warning:

    Warning If the destination file already exists, it will be overwritten.

    As a suggestion, always check that :

    isset($_FILES["FileInput"]) && $_FILES["FileInput"]["error"]== UPLOAD_ERR_OK)

    is true before continuing.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度