我想创建一个提供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.
更多推荐
如何将图像上传到另一台服务器?
发布评论