Hi I want to add some features in my new site. which fetch image and content automatically from the any url which is entered like digg. so can any one help me for that.
Hi, On dig what happens is users share the information that gets stored in the database of dig and then shown on its website. You can do this or if you do not want to save the information in your database you can use the file and CURL functions of PHP that will read the content of a URL passed and using regular expressions fetch the details or data you need from that website. Cheers, ~Maneet
It's easy to download any webpage using curl: <?php $curl = curl_init(); curl_setopt ($curl, CURLOPT_URL, "http://www.webpage.com"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec ($curl); curl_close ($curl); echo $result; ?> The output lays in $result, you can parse it further to extract any info you need.
http://www.w3schools.com/PHP/php_file_upload.asp Create The Upload Script, Restrictions on Upload, Saving the Uploaded File.......
for images (without content) <?php $sFile = "http://www.google.com/intl/en_ALL/images/logo.gif"; $imagedata = GetFileData($sFile); ob_start(); $length = strlen($imagedata); header('Last-Modified: '.date('r')); header('Accept-Ranges: bytes'); header('Content-Length: '.$length); header('Content-Type: image/gif'); print($imagedata); ob_end_flush(); function GetFileData($sFilePath){ $fp = fopen($sFilePath, 'rb') or die('404! Unable to open file!'); $buf = ''; while(!feof($fp)){ $buf .= fgets($fp, 4096); } fclose($fp); return $buf; } ?> PHP: you can change the header to header('Content-Type: image/gif'); to image/png or jpg (jpeg) etc for different pic formats ROOFIS
Nice coding, but what if i want to fetch images and content from other web page like digg and what should be added in mysql thanks for help
You can use bellow code, it can download any files : function downloadFile($url, $path) { $newfname = $path; $file = fopen ($url, "rb"); if ($file) { $newf = fopen ($newfname, "wb"); if ($newf) while(!feof($file)) { fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 ); } } if ($file) { fclose($file); } if ($newf) { fclose($newf); } } downloadFile('http://i.dpstatic.com/icon/icon4.png','icon4.png'); PHP: