Reputation:
I want to send data to my server via SSH. The data is image files that need to be saved into directories on the server.
If I run the script via SSH how can I get a PHP script to read the image files?
For example, if I used bash I could do
./uploadimage.bash -image.jpg
and that would be that. But my knowledge of PHP is limited. Usually PHP uses the $_FILE array when dealing with files, as far as I know. Do I need to use this if I send the files by SSH?
Upvotes: 0
Views: 6036
Reputation: 224904
It depends on what you need to do with the images.
Do you just need to echo them out to the user?
echo file_get_contents('image.jpg');
Are you meaning to retrieve the command-line variables passed to the script? Use $argv
.
myScript.php image.jpg # image.jpg becomes $argv[1]
Do you need to do processing on the images? Use the GD functions.
$image = imagecreatefromjpeg('image.jpg');
// Do processing
imagejpeg($image); // Pass a filename if you want to save it instead of output it.
Upvotes: 2
Reputation: 1635
If you want to simply upload a bunch of files to a remote server, your best bet is to use scp
command, rather than PHP
scp /your/file.png username@host:/remote/path.png
If you execute a PHP script through an SSH Session, there's no way you can send a file through SSH. You have to first copy it to the remote server and then execute the PHP which uses file_get_contents
or something like that.
If you are sure that PHP must be the recipient of the file (maybe you want to do some logic to determine the file name, path), you have to host it as a webserver, and you can use curl
to upload the file, like this:
curl -k -F [email protected] foo.php.
Upvotes: 0