谁能帮我实现如何将上传的文件从一台服务器移动到另一台服务器
我不是在谈论 move_uploaded_file() 函数。
例如,
If the image is uploaded from http://example.com
How can I move it to http://image.example.com
有可能吗?不是通过发送另一个帖子或提出请求吗?
最佳答案
获取上传的文件,将其移动到临时位置,然后将其推送到您喜欢的任何 FTP 帐户。
$tempName = tempnam(sys_get_temp_dir(), 'upload');
move_uploaded_file($_FILES["file"]["tmpname"], $tempName);
$handle = fopen("ftp://user:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e999889a9a9e869b8da98c91888499858cc78a8684" rel="noreferrer noopener nofollow">[email protected]</a>/somefile.txt", "w");
fwrite($handle, file_get_contents($uploadedFile));
fclose($handle);
unlink($tempName);
实际上,您甚至不需要 move_uploaded_file
部分。获取上传的文件并将其内容写入使用 fopen
打开的文件就完全足够了。有关使用 fopen
打开 URL 的更多信息,请参阅 php-documentation 。有关上传文件的更多信息,请参阅 File-Upload-Section PHP-Manual的
[编辑]在代码示例中添加了file_get_contents
[编辑]较短的示例
$handle = fopen("ftp://user:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a8d8c9dbdbdfc7dacce8cdd0c9c5d8c4cd86cbc7c5" rel="noreferrer noopener nofollow">[email protected]</a>/somefile.txt", "w");
fwrite($handle, file_get_contents($_FILES["file"]["tmpname"]);
fclose($handle);
// As the uploaded file has not been moved from the temporary folder
// it will be deleted from the server the moment the script is finished.
// So no cleaning up is required here.
关于apache - 如何在Php中将上传的文件移动到另一个主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16953543/