Results 1 to 3 of 3

Thread: PHP: Date Comaprison + Access External JPG file

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    266

    Question PHP: Date Comaprison + Access External JPG file

    Can you please tell me how do I compare two dates in PHP. Is there any in -build functions ?

    Also tell me how do I acces an external jpg file in a PHP source code.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: PHP: Date Comaprison + Access External JPG file

    1. In PHP dates a represented using a UNIX timestamp which is an integer corresponding to the number of seconds since 1/1/1970. To compare two dates, do what you would do when comparing numbers. The higher the number the larger the date. Have a glance at PHP's date and time functions.

    2. You can open an external JPG as if it were a standard file on the filesystem:
      PHP Code:
      $jpg file_get_contents('http://www.example.com/picture.jpg'); 
      The $jpg variable will now contain the binary data from the picture. If you wanted to display the picture you must then send the appropriate Content-Type header.
      PHP Code:
      header('Content-Type: image/jpeg');
      echo(
      $jpg); 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: PHP: Date Comaprison + Access External JPG file

    In reply to: http://www.vbforums.com/showthread.p...98#post2574998

    I already explained how to open a JPG. The file_get_contents() function is what you need, just replace the web address with the path to the file.

    If you look at the date/time functions I linked to previously you'll see that you need the [http://www.php.net/strtotime]strtotime()[/url] function to convert the date string into a timestamp which you can use for comparisons.

    The following constants will help:
    PHP Code:
    define('SECONDS_MINUTE'60);
    define('SECONDS_HOUR'SECONDS_MINUTE 60);
    define('SECONDS_DAY'SECONDS_HOUR 24);
    define('SECONDS_WEEK'SECONDS_DAY 7);
    define('SECONDS_YEAR'SECONDS_DAY 365);

    $difference $toDate $fromDate;

    // find the number of years
    $years = (int) ($difference SECONDS_YEAR);
    $remain $difference SECONDS_YEAR;

    // find the number of days - number of years
    $days = (int) ($remainSECONDS_DAY);
    $remain $remain SECONDS_DAY;

    // find the number of hours - number of days - number of years
    $hours $remain SECONDS_HOUR;

    echo(
    "$years years(s), $days day(s), $hours hour(s)"); 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width