Remote upload in PHP

Curl is your savior.

PHP:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_REFERER, 'https://google.com/');
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1");
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

$res = curl_exec($curl);
curl_close($curl);

// you can also check for status code to verify if the request was successful => curl_getinfo($curl, CURLINFO_HTTP_CODE)

$upload = file_put_contents("uploads/$name", $res);


If I wanted to create new folder for each file, how can I modify this code?

I tried this code, but it has folder permission to 0644 and doesn't upload the file
Code:
$name2 = str_replace(".mp3","", $name);

$folderName = "/home/user/public_html/music/songs/".$name2;
    

mkdir($folderName, 0777);



Thanks!!
 
Last edited:
Back
Top