php-general Digest 24 Jun 2007 09:33:25 -0000 Issue 4866

Topics (messages 257715 through 257721):

Convert Date time into Seconds
        257715 by: kvigor
        257716 by: Robert Cummings
        257717 by: kvigor

Hi. I need your help here
        257718 by: J S
        257720 by: Alan Milnes

Setting Different Temp Directory for Different Application Users
        257719 by: zareef.zareef.net

file_get_contents crash, if file is bigger than memory_limit
        257721 by: ecc

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
Good Day,

I'm chech if 24hrs has passed between these 2 datetimes:

$dTime1 = 2007-06-21 11:08:09;

$dTime2 = 2007-06-22 07:08:09;

I'd really like to convert the datetimes above into a format I can do 
regular math them.

Browsing around I've found the following code.  But both weren't clear on 
what to pass to them.  Because when I pass a datetime var to them and echo 
the value I get no output please help.
======================================================================
function datetime_to_epoch($date)
{
  $break = explode(" ", $date);
  $datebreak = explode("-", $break[0]);
  $time = explode(":", $break[1]);
  $epoch = date("U", 
mktime($time[0],$time[1],$time[2],$datebreak[1],$datebreak[2],$datebreak[0]));
  $datetime = date("Y-m-d H:i:s", 
mktime($time[0],$time[1],$time[2],$datebreak[1],$datebreak[2],$datebreak[0]));
}
?>
=======================================================================
function convert_datetime($varStamp) {

    list($date, $time) = explode(' ', $str);
    list($year, $month, $day) = explode('-', $date);
    list($hour, $minute, $second) = explode(':', $time);

    $timestamp = mktime($hour, $minute, $second, $month, $day, $year);

    return $timestamp;
}

//If anyone could elaborate, would be appreciated.
================================================================================
 

--- End Message ---
--- Begin Message ---
On Sat, 2007-06-23 at 21:29 -0500, kvigor wrote:
> Good Day,
> 
> I'm chech if 24hrs has passed between these 2 datetimes:
> 
> $dTime1 = 2007-06-21 11:08:09;
> 
> $dTime2 = 2007-06-22 07:08:09;
> 
> I'd really like to convert the datetimes above into a format I can do 
> regular math them.

<?php

echo ($foo = strtotime( '2007-06-21 11:08:09' ))."\n";
echo date( 'Y/m/d H:i:s', $foo )."\n";

?>

$foo contains a unix timestamp (the time in seconds since the Epoch).

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
Cool,

Like Ambien, It worked like a dream.


"Robert Cummings" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Sat, 2007-06-23 at 21:29 -0500, kvigor wrote:
>> Good Day,
>>
>> I'm chech if 24hrs has passed between these 2 datetimes:
>>
>> $dTime1 = 2007-06-21 11:08:09;
>>
>> $dTime2 = 2007-06-22 07:08:09;
>>
>> I'd really like to convert the datetimes above into a format I can do
>> regular math them.
>
> <?php
>
> echo ($foo = strtotime( '2007-06-21 11:08:09' ))."\n";
> echo date( 'Y/m/d H:i:s', $foo )."\n";
>
> ?>
>
> $foo contains a unix timestamp (the time in seconds since the Epoch).
>
> Cheers,
> Rob.
> -- 
> .------------------------------------------------------------.
> | InterJinn Application Framework - http://www.interjinn.com |
> :------------------------------------------------------------:
> | An application and templating framework for PHP. Boasting  |
> | a powerful, scalable system for accessing system services  |
> | such as forms, properties, sessions, and caches. InterJinn |
> | also provides an extremely flexible architecture for       |
> | creating re-usable components quickly and easily.          |
> `------------------------------------------------------------' 

--- End Message ---
--- Begin Message ---
Hi. I came across your contact info at php.zend.com and was hoping you could 
help me out with this question.
  I recently installed Rubberwall10, a free software that protects from 
hotlinking and although I managed to installed the software correctly at my 
site, I came across the fact that when I tried to download an image from the 
site to my computer, the image came out with 0 kbs.
   
  Someone who also installed the software made a comment on the internet 
stating he solved the problem adding a trim function to three of the variables 
in the filescrapper.php file. 
   
  My question to you is, how can I do that. I am not familiar with php, 
although I have understood some minimal basics. Adding trim function to $ct, 
$webaddress and $wantedfilename seemed to have solved the problem according to 
the user who solved the problem but did not specify how he did it. Can you tell 
me how I can add trim function to the above three variables?. Your help is 
greatly appreciated. The code is below. Thanks. John
  /***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/
$allowed = 0;
include('config.php');
  if($allowblank > 0) { if($_SERVER['HTTP_REFERER']=="") { $allowed = 1; }}
  $domains = count($alloweddomains);
  for($y=0;$y<$domains+1;$y++) {
 if((stristr($_SERVER['HTTP_REFERER'], $alloweddomains[$y]))) { $allowed = 1;}
}
  if($allowed > 0) {
      $namenumberarray = file($webaddress."fileindex.txt");
      $numberoffiles = count($namenumberarray);
      $filenames = array();
      
      for($x=0;$x<$numberoffiles+1;$x++) {
       $temporary = explode(":",$namenumberarray[$x]);
       $tempname = explode("\n",$temporary[1]);
       $filenames[$temporary[0]] = $tempname[0];
      }
      
      if(!isset($filenames[$_GET['serve']])) { 
       if($logging > 0){
        $status = "ReqNF";
        include('logit.php');
       }
       echo('That number wasnt found!');
       exit;
      }
      
      $wantedfilename = $filenames[$_GET['serve']];
              
              
      $extension = explode(".", $wantedfilename);
      $numberinarray = count($extension);
      
      $lcext = strtolower($extension[$numberinarray-1]);
      
      //BEGIN CONTENT TYPES BLOCK. ADD OR REMOVE FILE TYPES HERE, AS SHOWN //
      //DON'T EDIT THIS UNLESS YOU KNOW WHAT YOU ARE DOING!//
      //MOST COMMON FILE TYPES ARE ALREADY INCLUDED//
      
      switch($lcext) {
       case ($lcext == "swf"): 
        $commonname="flash"; 
        $ct = "Content-type: application/x-shockwave-flash";
       break;
       case ($lcext == "wmv"): 
        $commonname="wmv"; 
        $ct = "Content-type: video/x-ms-wmv";
       break;
       case ($lcext == "mov"): 
        $commonname="quicktime movie"; 
        $ct = "Content-type: video/quicktime";
       break;
       case ($lcext == "avi"): 
        $commonname="avi video"; 
        $ct = "Content-type: video/avi";
       break;
       case ($lcext == "rar"): 
        $commonname="winrar"; 
        $ct = "Content-type: application/octet-stream";
       break;
       case ($lcext == "zip"): 
        $commonname="zip"; 
        $ct = "Content-type: application/octet-stream";
       break;
       case ($lcext == "bmp"): 
        $commonname="bitmap"; 
        $ct = "Content-type: image/bmp";
       break;
       case ($lcext == "gif"): 
        $commonname="gif"; 
        $ct = "Content-type: image/gif";
       break;
       case ($lcext == "jpeg" || $lcext == "jpg" || $lcext == "jpe"): 
        $commonname="jpeg"; 
        $ct = "Content-type: image/jpeg";
       break;
       case ($lcext == "mpeg" || $lcext == "mpg" || $lcext == "mpe"): 
        $commonname="mpeg"; 
        $ct = "Content-type: video/mpeg";
       break;
       case ($lcext == "png"): 
        $commonname="png"; 
        $ct = "Content-type: image/png";
       break;
       
       //END//
       
       default: 
        $commonname="Generic Filetype"; 
        $ct = "Content-type: application/octet-stream";
        
        if($logging > 0){
         $status = "Generic_Filetype";
         include('logit.php');
        }
       
      }
      
      $handle = fopen($webaddress.$wantedfilename, "rb");
      header("Cache-Control: "); //keeps ie happy
      header("Pragma: "); //keeps ie happy
      header($ct); //content type as set above from explode();
      
      if(!stristr($lcext, "swf")){//flash plays, it isnt downloaded as an 
actual file.
       header("Content-Disposition: attachment; 
filename=\"".$wantedfilename."\"");
      }
      
      header("Content-Length: ".filesize($path.$wantedfilename));
      
      fpassthru($handle);
      if($logging > 0){
       $status = "Granted";
       include('logit.php');
      }
      exit;
}
  else {
 if($logging > 0){
  $status = "Denied";
  include('logit.php');
 }
 exit;
 //quiet leech kill
}
?>
   
   

       
---------------------------------
Moody friends. Drama queens. Your life? Nope! - their life, your story.
 Play Sims Stories at Yahoo! Games. 

--- End Message ---
--- Begin Message ---
Here are a couple of links that will help you:-

http://uk2.php.net/trim

http://www.catb.org/~esr/faqs/smart-questions.html

Alan

--- End Message ---
--- Begin Message ---
Hi All,


I want to set different temp directory to every users of my application. Is it possible. TEMP_DIR is only configurable at system level, so I can do it only in PHP.INI or in apache as PHP_VALUE.

Any Idea how this can be achieved using combination of things?

Thanks in Advance.

Zareef Ahmed

--- End Message ---
--- Begin Message ---
I really dont know, if this is the right board for this... but i think, i
have to write it down.

Please throw an error, if file_get_contents cant read a file because
memory_limit overflow!

I´ve programmed a tool parsing checksums from large files. Because i have to
manage header-offsets, i have to read the files using file_get_contents.
(This should be the fastest way for this task says the manual... right!)

The problem is, that if the memory_limit in the php.ini is set to 64MB, and
the file read in by file_get_contents is bigger than 64MB, file_get_contents
crashes without an EXCETPION. This crash cant be catched!

I want handle this this way:

try{
    $data = file_get_contents($file);
}
catch (MemoryLimitReachedException $e){
    // try the same using a while loop reading the data! (This works!)
}

Hope, there is a solution for this.

Thank you.
Andreas
http://www.php-gtk.eu/apps/emucontrolcenter

-- 
View this message in context: 
http://www.nabble.com/file_get_contents-crash%2C-if-file-is-bigger-than-memory_limit-tf3971711.html#a11273559
Sent from the PHP - General mailing list archive at Nabble.com.

--- End Message ---

Reply via email to