在PHP中将图像从一台服务器复制到另一台服

时间:2021-01-05 16:02:23

i have a web app in PHP on one server (ubuntu1), and i have a script to upload a image to one directory in the same server.

我在一台服务器(ubuntu1)上有一个PHP的Web应用程序,我有一个脚本将图像上传到同一服务器中的一个目录。

the problem is now we are moving the images to another server (ubuntu2).

问题是现在我们正在将图像移动到另一台服务器(ubuntu2)。

what is the best way to move the images to the new server?

将图像移动到新服务器的最佳方法是什么?

i was thinking, after the upload is complete use exec and scp to copy the image, for that i need to define one use in every server (ssh-keygen, pub key and authorized_keys files).

我在想,上传完成后使用exec和scp来复制图像,因为我需要在每个服务器中定义一个用法(ssh-keygen,pub key和authorized_keys文件)。

but

  • the user on ubuntu1 is www-data, and i think is not a good idea set up this user for ssh.

    ubuntu1上的用户是www-data,我认为为ssh设置此用户并不是一个好主意。

  • if i use "su user -c 'scp ....'", what about when the script ask for the password?

    如果我使用“su user -c'scp ....'”,那么当脚本要求输入密码时呢?

  • or another idea to do this?

    还是另外一个想法呢?

the copy is over internet.

副本是通过互联网。

1 个解决方案

#1


0  

If you have root access to your server, you could use the php_ssh2-Modul, which comes with a scp-Method. This way, you do not have to think that much about suing and other shell-related security issues.

如果您具有对服务器的root访问权限,则可以使用php_ssh2-Modul,它带有scp-Method。这样,您就不必过多考虑起诉和其他与shell相关的安全问题。

But maybe you could copy the file via cron later to the other server, so the user does not have to wait, until this job is done.

但也许您可以稍后通过cron将文件复制到另一台服务器,这样用户就不必等待,直到完成这项工作。

#1


0  

If you have root access to your server, you could use the php_ssh2-Modul, which comes with a scp-Method. This way, you do not have to think that much about suing and other shell-related security issues.

如果您具有对服务器的root访问权限,则可以使用php_ssh2-Modul,它带有scp-Method。这样,您就不必过多考虑起诉和其他与shell相关的安全问题。

But maybe you could copy the file via cron later to the other server, so the user does not have to wait, until this job is done.

但也许您可以稍后通过cron将文件复制到另一台服务器,这样用户就不必等待,直到完成这项工作。