I am currently implementing a new way for themes to be submitted on PS3 Themes. Allowing users to select a remote P3T file and it will be downloaded. There is multiple ways of doing this, but the simplest method is using cURL. The cURL options you will need are CURLOPT_TIMEOUT, CURLOPT_FILE and CURLOPT_FOLLOWLOCATION and you will need the function
fopen(). So here goes.
The code is fairly straight forward, and if not, the comments should help.
Highlighted using GeSHi
- $f = fopen('theme_name.p3t', 'w+'); // Initiate a file writer for the downloaded file to be written to.
- $d = curl_init('http://www.example.com/theme_name.p3t'); // initiate cURL on the file to download
- // set the appropriate options
- curl_setopt($d, CURLOPT_TIMEOUT, 60); // set the time out time for the cURL operation, the bigger the file, the bigger this number should be
- curl_setopt($d, CURLOPT_FILE, $f); // this is where you need the file handle, it will put everything straight handle
- curl_setopt($d, CURLOPT_FOLLOWLOCATION, true); // this is just so all redirects are actually, otherwise might get the wrong page.
- // Execute cURL, this will set it
- // close both the file handle and the cURL