|
|
|
|
|
|
| |
| <?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 | | | Simple pipe delimited file export program that downloads to a local machine Categories : PHP, Filesystem, Databases, MySQL, HTTP | | | 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 | | | PHP Domain Availability Checker Categories : PHP, Complete Programs, Regexps, HTTP, Sockets | | | Easy upload class Categories : PHP Classes, Filesystem, HTTP, PHP | | | 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 | | | Using php3 to upload files, uploading files, file uploads. Categories : PHP, Filesystem, HTTP | | | Random Image Display Categories : PHP, Filesystem, Graphics, HTML and PHP | | | PHP based Contact email form with multiple recipients, text file based, supports departments. Categories : PHP, Email, Beginner Guides, Filesystem | | | accept_connect -- Accepts a connection on a socket Categories : PHP, PHP Functions, Sockets | | | The toll booth Categories : PHP, Java Script, Filesystem | | | php jump urls...the best way Categories : PHP, URLs, Filesystem | | | Simple way to replace a variable value in a .conf (.ini) file using a
webbrowser - the first stage of a complete universal configuration editor Categories : PHP, Regexps, Code Editors, Filesystem | | | Display list of files within current and subdirectories (recursively) showing
each file as an anchored link and each directory as a category header. Categories : Filesystem, Directories, Arrays, PHP | |
|
|
|