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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵