Posts

Showing posts with the label curl

Remote File Download and upload directly to Server using PHP

Image
Sometime we require to Download some files from the remote location and upload it to our server, which is a time taking process. Here We are describing how to download and upload the file directly to our server using PHP. For this  to work , we will take the http location of the files and using the curl method , we will copy it to our server, so our downloading and uploading time will be saved, also it will be more fast , due to its directly copy the file from one remote server to another server. On this code , we have created a form and its take only HTTP url of the file. Here is the PHP code to do this: <html> <head> </head> <body> <?php if(isset($_POST['zip_file'])) { if(!is_dir("folder")) { mkdir("folder", 0755); } $url = $_POST['zip_file']; $newname = explode('/',$_POST['zip_file']);

Posting XML Data from PHP & curl

Image
There is a frequent need to post xml data to a url. Below is shown an example which lets you post xml data using CURL. <?php $url = "http://www.some_domain.com"; $post_string = '<?xml version="1.0" encoding="UTF-8"?> <rootNode> <innerNode> </innerNode> </rootNode>'; $header = "POST HTTP/1.0 \r\n"; $header .= "Content-type: text/xml \r\n"; $header .= "Content-length: ".strlen($post_string)." \r\n"; $header .= "Content-transfer-encoding: text \r\n"; $header .= "Connection: close \r\n\r\n"; $header .= $post_string; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 4); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header); $data = curl_exec($ch); if(curl_errno($ch)) print curl_error($ch); else curl_close($c