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.
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.
You can do it with secure SFTP:
PHP manual here: function.ssh2-scp-send.php
Or unsecure FTP:
PHP manual here: function.ftp-put.php
Or you could send HTTP request using PHP:
This is more like real web browser behavior as seen by another server:
You can use
socket_connect();andsocket_write();, I will add more information about those later.