WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Remote File Saving with PHP - Download and serve a remote file. The content of the file will be updated at fixed intervals.
Categories : PHP, Filesystem, Cache, Sockets, HTTP Click here to Update Your Picture
Sumit Agarwal
Date : Nov 24th 2007
Grade : 5 of 5 (graded 1 times)
Viewed : 19102
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Sumit Agarwal
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?php

// File to download
$remoteFile = 'http://www.yahoo.com/';

// Local file for saving
$localFile = "YahooHome.htm";

// Time to cache in hours
$cacheTime = 24;

// Connection time out
$connTimeout = 10;

if(
file_exists($localFile) && (time() - ($cacheTime * 3600) < filemtime($localFile))){
     
readfile($localFile);
}else{
     
$url = parse_url($remoteFile);
     
$host = $url['host'];
     
$path = isset($url['path']) ? $url['path'] : '/';

     if (isset(
$url['query'])) {
         
$path .= '?' . $url['query'];
     }

     
$port = isset($url['port']) ? $url['port'] : '80';

     
$fp = @fsockopen($host, '80', $errno, $errstr, $connTimeout );

     if(!
$fp){
         
// If connection failed, return the cached file
         
if(file_exists($localFile)){
               
readfile($localFile);
          }
     }else{
         
// Header Info
         
$header = "GET $path HTTP/1.0\r\n";
         
$header .= "Host: $host\r\n";
         
$header .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6\r\n";
         
$header .= "Accept: */*\r\n";
         
$header .= "Accept-Language: en-us,en;q=0.5\r\n";
         
$header .= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n";
         
$header .= "Keep-Alive: 300\r\n";
         
$header .= "Connection: keep-alive\r\n";
         
$header .= "Referer: http://$host\r\n\r\n";

           
$response = '';
         
fputs($fp, $header);
         
// Get the file content
         
while($line = fread($fp, 4096)){
               
$response .= $line;
          }
         
fclose( $fp );

         
// Remove Header Info
         
$pos = strpos($response, "\r\n\r\n");
         
$response = substr($response, $pos + 4);
          echo
$response;

         
// Save the file content
         
if(!file_exists($localFile)){
               
// Create the file, if it doesn't exist already
               
fopen($localFile, 'w');
          }
          if(
is_writable($localFile)) {
               if(
$fp = fopen($localFile, 'w')){
                   
fwrite($fp, $response);
                   
fclose($fp);
               }
          }
     }
}

?>



Remote File Size
Categories : PHP, Filesystem, HTTP, Sockets
Class that allows the PHP developer to create and manage UNIX like password files suitable for use as Apache authentication password files.
Categories : HTTP, PHP, PHP Classes, Filesystem
Using php3 to upload files, uploading files, file uploads.
Categories : PHP, Filesystem, HTTP
PHP Domain Availability Checker
Categories : PHP, Complete Programs, Regexps, HTTP, Sockets
Easy upload class
Categories : PHP Classes, Filesystem, HTTP, PHP
Simple pipe delimited file export program that downloads to a local machine
Categories : PHP, Filesystem, Databases, MySQL, HTTP
Force file download
Categories : PHP, Filesystem, HTTP, Program Execution
How to let a user download a picture by clicking on it instead of needing to right click and Save-As.
Categories : HTTP, PHP, HTML and PHP, Filesystem
This script will read all images from a folder and read the files into an array. It uses rand() to get a random number. It will display a random image from the image folder given.
Categories : PHP, Arrays, Graphics, Filesystem
File Explorer, browse, upload, download and edit your web site files with only a browser and a HTTP connection.
Categories : Complete Programs, Content Management, Filesystem, PHP
A simple php file uploader
Categories : PHP, Filesystem, HTML and PHP
IP Blocking
Categories : PHP, Security, HTTP
The simple counter with use MySql and gd.
Categories : MySQL, HTTP, Graphics, PHP, Databases
HTTP Basic Authentication via POP3.
Categories : Authentication, HTTP, Email, PHP
3 lines of Code to extract Tar, Zip, Gzip etc..
Categories : PHP, Filesystem, PHP Classes, Compression