简体   繁体   English

文件上传并保存到另一台服务器PHP

[英]File Upload and Save on another Server PHP

I currently collect and upload an image using a form on one server (server A), I would like to store it on another server (server B). 我目前正在使用表单在一个服务器(服务器A)上收集和上传图像,我想将其存储在另一台服务器(服务器B)上。 From the examples I have seen, I would need to save the file and then copy it over using either copy or curl. 从我所看到的示例中,我需要保存文件,然后使用复制或curl进行复制。

I would like to get the file that I receive on server A and send it to server B without actually saving the file on server A. Is there a way for me to do this? 我想获取在服务器A上接收到的文件,然后将其发送到服务器B,而实际上没有将文件保存在服务器A上。我有办法吗? I tried converting the file to a dataURI string and sending it this way, however I think the string is too long and I am getting errors with this. 我尝试将文件转换为dataURI字符串并以这种方式发送,但是我认为该字符串太长,因此出现错误。 Thank you in advance for your help! 预先感谢您的帮助!

UPDATE I found my solution lovers! 更新我找到了我的解决方案爱好者! The file is stored in temporary storage when uploaded. 上载时,文件存储在临时存储器中。 You can't use just the filename to save the file on a different server, but you can use the information to create a CurlFile, which can then be passed to your page on the other server to be created (See Shivani Patel's response to PHP: upload file from one server to another server ). 您不仅可以使用文件名将文件保存在其他服务器上,还可以使用该信息创建一个CurlFile,然后将其传递到要创建的另一台服务器上的页面(请参阅Shivani Patel对PHP的回复) :将文件从一台服务器上传到另一台服务器 )。 This combined with information from http://blog.derakkilgo.com/2009/06/07/send-a-file-via-post-with-curl-and-php/ and I got my code working. 这与来自http://blog.derakkilgo.com/2009/06/07/send-a-file-via-post-with-curl-and-php/的信息结合在一起,我的代码可以正常工作。

Please mark as duplicate if appropriate. 如果合适,请标记为重复。 I didn't think to look into the temp filename until suggested :) 直到提出建议,我才认为要研究临时文件名:)

You can make use of ftp_put() function as follows 您可以使用ftp_put()函数,如下所示

// information of second server
$ftp_server = "ftp.example.com";
// name file in serverA that you want to store file in serverB
$file = 'somefile.png';
$remote_file = 'serverB_file.png';

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
 echo "successfully uploaded $file\n";
} else {
 echo "There was a problem while uploading $file\n";
}

I have also gone same thing.. first i moveuploaded file in serverA and then transfer in serverB,,, after complete transfer unlink the file in serverA. 我也做了同样的事情..首先,我在serverA中移动了上载的文件,然后在serverB中进行了传输,完成传输后,取消了serverA中的文件链接。

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

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