简体   繁体   English

直接在FTP服务器中上载/放入文件,而用户将以网页形式上载

[英]Upload/Put file Directly in FTP server while user will upload in webpage form

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 ? 我想知道用户是否有可能在网页表单控件中上传任何文件(JPG,JPEG,PDF,Zip等),而该文件将直接上传/放置到FTP服务器上而无需在其中存储第一个临时文件网站服务器然后在FTP服务器上传输?

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. 实际上,我有一个业务案例,用户可以上传超过200 MB的文件,因此在这里我想直接将其传输到远程FTP服务器中而不将其存储在网站服务器中。

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. 我进一步调查了html表单标签允许“操作”属性中的FTP协议,下面是我尝试过的代码片段。

<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. 但是,当我尝试上传图像并提交图像时,它会将我重定向到浏览器中的ftp:// username:password@domainname/upload.php URL中,这将显示我在upload.php中编写的PHP代码文件。

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. 实际上,我已经知道,一旦表单提交并将文件从服务器临时位置($ _FILES ['uploadedfile'] ['tmp_name'])传输到FTP服务器,如何在远程FTP服务器中传输文件,但是通过这样做,它将首先将文件上传到网站服务器,然后再在远程FTP服务器中进行传输,这需要两倍的时间。

You can also suggest me the alternative way to achieve my business need. 您也可以向我建议实现我的业务需求的另一种方法。

Thanks in advance. 提前致谢。

You can use ftp_put(). 您可以使用ftp_put()。 http://php.net/manual/en/function.ftp-put.php http://php.net/manual/en/function.ftp-put.php

Here's what your start of a .php file might look like: .php文件的开头如下所示:

<?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) //要将文件扔到Web服务器上的位置(相对于登录目录)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM