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 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀