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 : Check for functional file links (broken Files)
Categories : PHP, Data Validation, FTP, Regexps, Arrays Click here to Update Your Picture
Dave Silvia
Date : Nov 10th 2006
Grade : 2 of 5 (graded 2 times)
Viewed : 7181
File : 4527.php
Images : No Images for this code example.
Search : More code by Dave Silvia
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

Validate that a link to a file is reachable
(c) 2006, D.E. Silvia, All rights reserved.
This code is available for use for non-commercial purposes.
Free to distribute as long as this copyright information remains intact.
No modification is authorized. Please, refer bugs/enhancements to
dsilvia@mchsi.com


Function to check for functional file links

Allows you to check legitimacy of user input for links. You could also place in
crontab (Uinices) or Scheduled Tasks (Windows) to periodically verify the links
you have in place.

A simple example of usage is included in the comment below, simply uncomment it
as indicated for a demonstration of how the code works.

Function has a single argument, $file, which is the url to the linked file.
Return is boolean 'true', 'false', error array, or short string describing the error.
Errors:
false: ftp_connect() failed
array: error# and error string from fsockopen()
string: "No path in ftp url"
"[Ftp ]File Not Found"


brokenFileLink.php
<?php
$fileAry
[0]='http://weberforums.com/index.php';
$fileAry[1]='http://weberdev.com/index.html';
$fileAry[2]='http://www.google.com/advanced_search?q=windows+xp&hl=en&lr=lang_en&as_qdr=m3';
$fileAry[3]='ftp://anonymous:anonymous@mirror.services.wisc.edu/pub/mirrors/mysql/Downloads/MySQL-5.0/mysql-5.0.26-win32.zip';
$fileAry[4]='ftp://mirrors.24-7-solutions.net/pub/mysql/Downloads/MySQL-5.0/mysql-5.0.26-win32.zip';
$fileAry[5]='ftp://anonymous:anonymous@ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-6.7.tar.gz';
$fileAry[6]='ftp://mirror.services.wisc.edu';
for(
$i=0; $i < count($fileAry); $i++)
{
   
$file=$fileAry[$i];
    print(
"<h4>File: $file</h4>");
   
flush();
   
$linkBroken=brokenLink($file);
    if(
$linkBroken)
    {
        print(
"Link to $file is broken<br />");
        if(
is_array($linkBroken)) print("Problem with host: errno#".$linkBroken[0].", error:".$linkBroken[1]."<br />");
        else print(
"Problem with file: $linkBroken<br />");
       
flush();
    }
    else
    {
        print(
"Link to $file is okay<br />");
       
flush();
    }
}

/*
*
*/
function brokenLink($file)
{
   
$urlAry=parse_url($file);
   
$host=$urlAry['host'];
   
$scheme=$urlAry['scheme'];
   
// set these however you like. The old 'anonymous/anonymous'
    // will not work on many sites as they expect an email format
    // for the password.
   
if(isset($urlAry['user'])) $ftpUser=$urlAry['user']; else $ftpUser='anonymous';
    if(isset(
$urlAry['pass'])) $ftpPass=$urlAry['pass']; else $ftpPass='me@home';

    if(!isset(
$urlAry['path'])) return "No path in url";
   
$isFTP=!strcmp(substr($scheme,0,3),"ftp");

   
$ret=false;
   
$ftpRet=array();
    if(
strcmp(substr($scheme,0,3),"ftp") == 0)
    {
       
$fp=@ftp_connect($host);
        if(
$fp)
        {
           
$ftpLogin=ftp_login($fp,$ftpUser,$ftpPass);
            if(
$ftpLogin)
            {
               
$ftpFile=$urlAry['path'];
               
$ftpFileAry=split('/',$ftpFile);
               
$numDirs=count($ftpFileAry)-1;
                for(
$i=0; $i < $numDirs; $i++)
                {
                   
$ftpRet=ftp_raw($fp,"cwd ".$ftpFileAry[$i]);
                }
               
$ftpRet=ftp_nlist($fp,'.');
               
$ftpRet=preg_grep('/^'.$ftpFileAry[$numDirs].'$/',$ftpRet);
                if(
$ftpRet == array()) $ret="Ftp File not Found";
            }
        }
    }
    else
    {
       
$sp=@fsockopen($host,80,$errno,$errstr);
        if(!
$sp) $ret=array($errno,$errstr);
        else
        {
           
fclose($sp);
           
$linkFile=@fopen($file,"r");
            if(!
$linkFile) $ret="File not Found";
            else
fclose($linkFile);
        }
    }
    return
$ret;
}
?>



Tag content retrieval from websites with preg_match
Categories : PHP, Regexps, Arrays, HTML and PHP
PHP Script to find url links in a page
Categories : PHP, URLs, Regexps, Arrays
columned txt file to array()?
Categories : Arrays, Strings, Regexps, PHP
An array of functions to use in checking user input to HTML forms : text, firstName, middleNameOrInit, lastName, email, web, digits, decimal, hex, genNum, USD, BPS, Euro, USphone, USzip
Categories : PHP, Data Validation, Regexps
Banknote Validation - A PHP class that provides several methods to quickly validate banknote serial numbers of the following currencies: AUD, CAD, CHF, CNY, EUR, GBP, JPY, USD.
Categories : PHP, PHP Classes, Data Validation, Regexps
Validating a URL with preg_match
Categories : PHP, Regexps, Beginner Guides, Data Validation
grab the result of any calculation you submit to the Google Calculator.
Categories : PHP, Arrays, Web Services, Regexps, Math.
Check if a file exists on a remote FTP server with PHP
Categories : PHP, FTP, Regexps
BBCode Formatting String
Categories : PHP, HTML, Regexps, Arrays
ftp_cdup -- Changes to the parent directory
Categories : PHP, PHP Functions, FTP
How to check if a file is of type gif or jpg?
Categories : PHP, Regexps, Graphics
PHPDRAW, the php wannabe Photoshop ;-)
Categories : PHP, PHP Classes, GD image library, Arrays
A simple bubblesort that takes 2 arrays as argument.The first one is the actual data used for sorting, the second is data that will "tag along" with the first array, for instance a descriptive text about the data in the first array.
Categories : Algorithms, Arrays, PHP, Complete Programs
Parsing html tags with php. Get an array from this function
Categories : PHP, HTML and PHP, Arrays, Tag Extractors
FormChecker Package - validate any data via classes and patterns.
Categories : PHP, Form Processing, PHP Classes, Regexps