如何将图像上传到另一台服务器? [英] How to upload image to another server?

查看:94
本文介绍了如何将图像上传到另一台服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个提供html内容的应用程序服务器,其中包含指向不同域中另一台服务器提供的静态图像的链接.图像由用户通过应用程序服务器上载.

I want to create an application server that serves html content which contains links to static images served by another server on a different domain. The images are uploaded by users through the application server.

这是我将JPEG文件上传到应用程序服务器的操作:

This is what I would do to upload a JPEG file to the application server:

if(!file_exists("folder_name")) mkdir("folder_name", 0770);
$temp_file = $_FILES['image']['tmp_name'];
$im = imagecreatefromjpeg($temp_file);
$destination = "folder_name/file_name.jpg";
imagejpeg($im, $destination);
imagedestroy($im);

如果我将文件上传到另一台服务器,将如何更改代码?

How would the code be changed if I were to upload the file to another server instead?

添加注释:如果文件夹不存在,则要即时创建.

Add Note: The folders are to be created on the fly if it doesn't exist.

推荐答案

主要取决于您可以使用什么.

Mostly depends on what you can use.

$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');

ssh2_scp_send($connection, '/local/filename', '/remote/filename', 0644);

此处的PHP手册: function.ssh2-scp-send.php

$file = 'somefile.txt';
$remote_file = 'readme.txt';

// set up basic connection
$conn_id = ftp_connect("ftp.example.com");

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

// 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";
}

// close the connection
ftp_close($conn_id);

此处的PHP手册: function.ftp-put.php

这更像是另一台服务器看到的实际Web浏览器行为:

This is more like real web browser behavior as seen by another server:

您可以使用socket_connect();socket_write();,稍后我将添加有关这些的更多信息.

You can use socket_connect(); and socket_write();, I will add more information about those later.

这篇关于如何将图像上传到另一台服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆