Send file to remote server with PHP

Asked

Viewed 769 times

3

I have a PHP system that I developed and put online on my server at Digitalocean, the site has two parts, which visitors will access and the administration area where I manage this site and put the content to which users will have access.

I left the administration area on my local machine for security reasons since only I could access it and I would have no reason to askla online, I made the connection to the database that is in Digitalocean with the admin area that is on my local machine and everything works perfectly, only that has a problem that I do not know how to solve.

I need when I register information to send images of the items I register in the system, then that’s the problem, I don’t know how to do, and to make safely posting these images from my local machine to my Linux server at Digitalocean, currently I send these images commiting to my local Git repository to my remote git server, which is extremely wrong and makes me have to commit at all times when I register new items simply so that images are sent.

How can I upload these images using PHP language securely to my remote server?

NOTE: My server at Digitalocean I only access it via SSH from my linux terminal on the local machine, it would have to be a way to allow this upload with an active SSH server on the remote server

  • Does it have any file storage service, just like Amazon has S3?? If so, it must have some documentation on how to use the API to upload.

  • you have tried with Curl?

  • I honestly can’t answer you, see, when I upload via git the clays are sent to my DO server, what I want is to do this but n via GIT and yes via form in my administration area on my local machine and that this file goes to a folder there on my machine like any other file, are just JPG images

  • Possible duplicate of Upload to another server error

  • this example that you cited n applies to my case, I have a linux server that can only be accessed via SSH, this solution that was presented there in this post does not work with me, I tested it, if you test and get a different result please share here

2 answers

5


The rsync, for Gnu/Linux, perform synchronization between folders, so whenever you add images in your local folder they will be sent to the remote directory. It is also possible to configure it in order to avoid duplication and backup.

If you are a Windows user, you can count on Winscp that enables the same functionalities.

  • 1

    I will test this feature, if it works can solve the problem at least temporarily

  • It took but tested, kkkkkkkkkkk, it worked and I think it will solve my problem at least temporarily until I can do it the way I want via PHP, obg.

2

Outside of the application, as you have done, the ideal would be to use SFTP. I particularly do not use Digital Ocean, but everywhere I use FTP and SFTP I give preference to Filezilla.

These articles will be useful:

Inside the application, you can also make it use SFTP and upload, obviously a job but it will be nice, certainly.

Here you can use the PHP SSH2 extension, but it is not installed by default, or use an external library like phpseclib.

There is an issue in Stackoverflow in English with two good examples using both solutions, and I take advantage and put link to a comment that shows accessing the server accessing the keys, no need for password.

    • http://stackoverflow.com/questions/4689540/how-to-sftp-with-php - http://php.net/manual/en/function.ssh2-connect.php#104758

Browser other questions tagged

You are not signed in. Login or sign up in order to post.