如何将图像上传到另一台服务器?

编程入门 行业动态 更新时间:2024-10-28 10:33:52
本文介绍了如何将图像上传到另一台服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想创建一个提供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', 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"); // 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.

更多推荐

如何将图像上传到另一台服务器?

本文发布于:2023-10-10 01:03:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1477271.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   另一台   图像   服务器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!