douhu1990 2015-06-16 17:48
浏览 41

PHP csv上传文件不在服务器上

I wrote a simple script to upload a csv file and then update a database table. However, even though I am getting a temp $_FILES['update']['tmp_name'] path, the file is not at this location on the server. Does anyone know what this means? could it be a permissions issue? This is a Godaddy shared hosting account.

Here's my form and the handler (the database piece is not in place yet. I'm just trying to get file contents at this point):

<div class="admin-section" style="margin-left:10%;">
    <?php
        if ( !empty($_POST['uploadFile']) ) {
            $name = $_FILES['update']['name'];
            echo $_FILES['update']['type'] . '<br />';
            echo $_FILES['update']['size'] . '<br />';
            $path = $_FILES['update']['tmp_name'];
            echo $_FILES['update']['error'] . '<br />';

            $file = $path . '/' . $name;
            $file_open = fopen($file, 'r');
            $data = fgetcsv( $file_open, 1000, ',');
            print_r($data);
        }
    ?>
    <form enctype="multipart/form-data" action="#" method=post>
        <label>Select a CSV or XLS file to up load from your computer</label><br />
        <p>
            <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
            <input type="hidden" name="uploadFile" value="yes" />
            <input type=file name=update />
        </p>
        <p>
            <input type=submit name=Upload />
        </p>
    </form>
</div>

The error I get is fopen(/tmp/php05Lebo/certificate-users.csv): failed to open stream: No such file or directory, and sure enough, that folder does not exist in /tmp. Thanks!

  • 写回答

1条回答 默认 最新

  • douhuanqiao5290 2015-06-16 18:28
    关注

    You never moved the temp file to the $file path, so your $file is invalid. Either use move_uploaded_file() to rename the temp file and save it on your server or if you don't care about accessing the file after the initial upload, set $file = $_FILES['update']['tmp_name']

    <?php
        if ( !empty($_POST['uploadFile']) ) {
            $name = $_FILES['update']['name'];
            echo $_FILES['update']['type'] . '<br />';
            echo $_FILES['update']['size'] . '<br />';
            $path = $_FILES['update']['tmp_name'];
            echo $_FILES['update']['error'] . '<br />';
            if(move_uploaded_file($_FILES['update']['tmp_name']),$name){
                $file_open = fopen($name, 'r');
                $data = fgetcsv( $file_open, 1000, ',');
                print_r($data);
            }else
               echo 'Unable to upload file';
        }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services