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 halcon联合c#遇到了问题不能解决
  • ¥15 xshell无法连接提示ssh服务器拒绝密码
  • ¥15 AT89C52单片机C语言关于串口通信的位操作
  • ¥20 需要步骤截图(标签-服务器|关键词-map)
  • ¥50 gki vendor hook
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 这是一个利用ESP32自带按键和LED控制的录像代码,编译过程出现问题,请解决并且指出错误,指导如何处理 ,协助完成代码并上传代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。
  • ¥20 求结果和代码,sas利用OPTEX程序和D-efficiency生成正交集
  • ¥50 adb连接不到手机是怎么回事?