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";
        }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题