By using an url wrapper, you can use your default move_uploaded_file(), if your ftp server accepts this connection type. Alternatively, you can use PHP's ftp functions, especially ftp_put(), to upload the file to the server.
For content delivery, you need to have a database or other means to get the original 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>
An example code to handle an uploaded files would 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 with 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 ...
}
}