Pages

Thursday, February 2, 2017

Upload file from url in PHP via Curl




 $ch = curl_init();
            $source = 
'http://website.com/filename.jpg';
            $path_parts = pathinfo('http://website.com/filename.jpg');
            curl_setopt($ch, CURLOPT_URL, $source);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $data = curl_exec ($ch);
            curl_close ($ch);

           // Your File Path and Filename here

            echo $destination = "./fileuplods/".$path_parts['filename'].'.'.$path_parts['extension'];
            $file = fopen($destination, "w+");
            fputs($file, $data);
            fclose($file);

No comments:

Post a Comment