Using url wrapper , you can use your default move_uploaded_file <) if your ftp server accepts this type of connection. Alternatively, you can use PHP ftp functions , especially ftp_put () , to upload the file to the server.
To deliver content, you need to have a database or other means to get the source URL on the content distribution server and put the URL in the html arguments:
<img src="http://cdn1.example.com/images/68263483.png" /> <a href="http://cdn2.example.com/files/9872345.pdf">Download PDF</a>
Sample code for processing uploaded files will be
<?php // ... $uploads_dir = 'images'; foreach ($_FILES["pictures"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["pictures"]["tmp_name"][$key]; $name = $_FILES["pictures"]["name"][$key]; move_uploaded_file($tmp_name, "ftp://user: pass@cdn1.example.com /$uploads_dir/$name"); // save url in your database for later retrieval ... } }
or ftp_put () :
<?php // ... $ftpCon = ftp_connect('cdn1.example.com') or die('Could not connect to ftp server'); $uploads_dir = 'images'; foreach ($_FILES["pictures"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["pictures"]["tmp_name"][$key]; $name = $_FILES["pictures"]["name"][$key]; ftp_put($ftpCon, "$uploads_dir/$name", $tmp_name) or die("could not upload $name to ftp server"); // save url in your database for later retrieval ... } }
source share