Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Development: How can I allow a user to upload files directly to my CDN (Cachefly)?

I have a PHP web-application that allows users to upload images to my web site. I'm doing this using a simply HTML <form enctype="multipart/form-data">

However, instead of having those images uploaded to my web server - I would to have those images uploaded directly to my CDN (Cachefly - which is another server).

Is this possible ... to have a web-application allow a user to upload images directly to another server?

In case it helps, here's my PHP code:

$target_path = "/home/www/example.com/uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    // file has been uploaded **LOCALLY**
    // HOWEVER, instead of it being upload locally, I would like the file 
    // to be directly uploaded to the CDN ('other' server)
    ...
} else{
    // error: file did not get uploaded correctly
    ....
}
like image 935
Tim Avatar asked Oct 15 '09 19:10

Tim


People also ask

How do I allow files to upload to my website?

If you want to allow a user to upload an external file to your website, you need to use a file upload box, also known as a file select box. This is also created using the <input> element but type attribute is set to file.

How do I upload contents to CDN?

There are two ways you can serve data from most CDNs: Using a pull zone: This pulls existing content from your origin server and caches it on the CDN's PoPs. Using a push zone: You manually upload content to the CDNs storage cluster and from there the content gets distributed to the CDN's PoPs.

Can Cdn be used for upload?

Essentially, CDNs are a cluster of servers that communicate with each other to pass your content around. Having factored everything in, CDN upload file exists so that developers can integrate their own file upload services and widgets to whichever CDN providers they're subscribed to.

How do I let users upload files to my HTML website?

HTML allows you to add the file upload functionality to your website by adding a file upload button to your webpage with the help of the <input> tag. The <input type=”file”> defines a file-select field and a “Browse“ button for file uploads.


3 Answers

i think in case of a CDN ... u will first have to receive files on ur server and then using the CDN API upload to their 'bucket'. i dont think u can upload directly to a CDN unless there is a way to map it as a directory on ur server.

like image 101
Sabeen Malik Avatar answered Sep 19 '22 07:09

Sabeen Malik


  • Moving / Uploading a file to a service or for you non-direct-accesable server is usually done by using the provider's API
  • Moving / Uploading a file to a server 'owned' by yourself can be done by using PHP + FTP extensions (for more information: pear.php.net or pecl.php.net)
  • Moving / Uploading a file to a server 'owned' by yourself and being one of many in a cluster is usually done by uploading the file temporary on 1 server and afterwards a .sh, .bash or whatever is called which activates further transfer processes to another server.
like image 21
Julius F Avatar answered Sep 22 '22 07:09

Julius F


I don't think it's possible to directly upload to another server, but I could be wrong. I had a similar problem, and I used PHP's FTP capabilities (http://us3.php.net/manual/en/book.ftp.php). I still used my server as a middle-man, meaning I uploaded the files to my server, then FTP transferred them to the target server, and then deleted the file from my server.

like image 45
Steven Mercatante Avatar answered Sep 19 '22 07:09

Steven Mercatante