dongzhan1570 2015-08-12 10:21
浏览 1079

上传/放置文件直接在FTP服务器上,用户将以网页形式上传

I would like to know that is there any possibility that whatever (JPG, JPEG, PDF, Zip etc..) file will be uploaded by the user in webpage form control that will directly upload/Put on the FTP server without storing first temporary in website server and then transfer in FTP server ?

Actually i have a business case that user can able to upload more then 200 MB of file so here i would like to directly transfer it in Remote FTP server without storing it in website server.

further i have investigated that html form tag allow the FTP protocol in Action attribute and below are the code snipped which i have tried.

<form action="ftp://username:password@domainname/upload.php" enctype="multipart/form-data" method="post">
    <table style="border-collapse: collapse;" border="1" width="500px">
        <tbody><tr>
            <td> Upload File :</td>
            <td> <input name="uploadedfile" type="file"> </td>
        </tr>
        <tr>
            <td colspan="2">
             <input name="Save File" value="Save File on Server" type="submit">
            </td>
        </tr>     
    </tbody></table>
</form>

But when i am trying to upload the image and submit it then it redirect me into the ftp://username:password@domainname/upload.php url in browser and that will display the PHP code which i have scripted inside the upload.php file.

Actually I already aware that how to transfer the file in Remote FTP server once the form submit and transfer the file from server temporary location ($_FILES['uploadedfile']['tmp_name']) to FTP server but by doing this way it will take double time as first the file getting uploaded in website server and then further transfer in Remote FTP server.

You can also suggest me the alternative way to achieve my business need.

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • doqw89029 2015-08-12 10:32
    关注

    You can use ftp_put(). http://php.net/manual/en/function.ftp-put.php

    Here's what your start of a .php file might look like:

    <?PHP
       $myFile = $_FILES['file_name']; // This will make an array out of the file information that was stored.
    ?>
    

    Now when it comes to transmitting that information...

    <?PHP
            $destination_path = "src/bin/"; 
    

    //where you want to throw the file on the webserver (relative to your login dir)

    $destination_file = $destination_path."img.jpg";
    

    //This will create a full path with the file on the end for you to use, like splitting the variables like this in case I need to use on on their own or if dynamically creating new folders.

    $file = $myFile['tmp_name'];
    

    //Converts the array into a new string containing the path name on the server where your file is.

        $upload = ftp_put($conn_id, $destination_file, $file, FTP_BINARY);// upload the file
        if (!$upload) {// check upload status
            echo "FTP upload of $destination_file has failed!";
        } else {
            echo "Uploaded $file to $conn_id as $destination_file";
        }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)