Programming, website development forum Get latest updates by RSS Follow TechnicalTalk on Twitter Follow TechnicalTalk on Facebook 
HomeSearchRecent PostsLoginRegisterContact Us

Username  
Password    
  Forgot your password?  

Pages: [1]   Go Down
 
  Email this topic  |  Print
0 Members and 1 Guest are viewing this topic.

How to fetch Image using PHP

 
webmaster forum
Activity
0%
 
New Poster
Posts: 9
Topics: 5
WWW
March 22, 2010, 12:53:00 AM

Hello everyone

I wanna add some new features in my site, i want to featch imgae and content automaticaly from the any url which entered like some social bookmarking site for example Digg. 

Any one can please help me how can i do it.

Thanks in advance.
 
webmaster forum
waitely  Offline
Activity
0%
 
New Poster
Posts: 3
Topics: 0
March 17, 2011, 02:09:18 AM

The code on this page displays an image selected at random using PHP.  The list of images for this example comes from a directory listing.

The code for this example:

Code:

<?php 
function getRandomFromArray($ar) { 
    
mt_srand( (double)microtime() * 1000000 ); 
    
$num array_rand($ar); 
    return 
$ar[$num]; 


function 
getImagesFromDir($path) { 
    
$images = array(); 
    if ( 
$img_dir = @opendir($path) ) { 
        while ( 
false !== ($img_file readdir($img_dir)) ) { 
            
// checks for gif, jpg, png 
            
if ( preg_match("/(\. gif|\. jpg|\. png)$/"$img_file) ) { 
                
$images[] = $img_file
            } 
        } 
        
closedir($img_dir); 
    } 
    return 
$images


$root ''
// If images not in sub directory of current directory specify root  
//$root = $_SERVER['DOCUMENT_ROOT']; 

$path 'images/'

// Obtain list of images from directory  
$imgList getImagesFromDir($root .  $path); 

$img getRandomFromArray($imgList); 

?>




Place the following where you wish the random image to appear:
<img src="<?php echo $path .  $img ?>" alt="" />


« Last Edit: October 22, 2011, 10:33:01 PM by Admin »
 
webmaster forum
Activity
100%
 
Regular Coder
Posts: 88
Topics: 1
WWW
December 08, 2011, 01:31:54 AM

Try this may be it help full to you.

Code:

function save_image($img,$fullpath){
    $ch = curl_init ($img);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
    $rawdata=curl_exec($ch);
    curl_close ($ch);
    if(file_exists($fullpath)){
        unlink($fullpath);
    }
    $fp = fopen($fullpath,'x');
    fwrite($fp, $rawdata);
    fclose($fp);
}

« Last Edit: December 15, 2011, 05:53:01 AM by Admin »

Web Design Delhi | Website Design Delhi | Website Design Company Delhi
 
webmaster forum
Activity
100%
 
Regular Coder
Posts: 77
Topics: 0
January 07, 2012, 09:49:03 AM

Code:
<?php
$curl 
curl_init();
curl_setopt ($curlCURLOPT_URL"http://www.webpage.com");
curl_setopt($curlCURLOPT_RETURNTRANSFER1);
$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.

Yellow Pages of Pakistan
 
webmaster forum
mallory  Offline
Activity
40%
 
New Coder
Posts: 39
Topics: 7
February 01, 2012, 02:03:25 AM

Code:
<?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($fp4096);
    }
    
fclose($fp);
return 
$buf;
}
?>

online email marketing | web designers in chennai
 
  Email this topic  |  Print
Pages: [1]   Go Up
 
Jump to:  



Powered by SMF 1.1.15 | SMF © 2011, Simple Machines


Google visited last this page February 05, 2012, 05:43:54 PM