php-general Digest 22 Apr 2007 23:47:37 -0000 Issue 4750

Topics (messages 253484 through 253499):

Re: echo date('Y-m-d', $mydata->timestamp);
        253484 by: Børge Holen
        253486 by: Jochem Maas

Re: retrieve POST body?
        253485 by: Myron Turner

Re: show file creation date
        253487 by: tedd
        253488 by: Colin Guthrie

Re: how to detect type of image
        253489 by: Jonathan
        253490 by: Børge Holen
        253492 by: Myron Turner
        253493 by: Tijnema !

Re: php seems to be inconsistent in its handling of backslashes ... maybe?
        253491 by: Al
        253495 by: ufan100.gmail.com

PhpMyAdmin slow on windows but fast on linux
        253494 by: Don Don
        253496 by: Børge Holen
        253497 by: Buesching, Logan J

Best practices to ensure compatibility with PHP 6
        253498 by: ufan100.gmail.com

Why do i get this error message?
        253499 by: H.T

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 ---
On Sunday 22 April 2007 08:33, John Taylor-Johnston wrote:
> It is actually a generated timestamp in MySQL.
> timestamp(14)

Well, then just use the query to decide how it should look like.
Mysql timestamp is amazingly easy to work with.
whatevertable,date_format(timestamp_table, 'what should it look like') as 
timestamp or use another name if you need both like I do.

>
> Now what? I was hoping to avoid:
> |echo substr(|$mydata->timestamp|, 0, 8);
>
> John
>
> |Richard Lynch wrote:
> |
> > On Sun, April 22, 2007 1:05 am, John Taylor-Johnston wrote:
> >> $mydata->timestamp = "20070419162123";
> >>
> >> echo date('Y-m-d', $mydata->timestamp);
> >>
> >>
> >> result: 2038-01-18
> >>
> >> ?? What is wrong?? Should be 2007-04-19?
> >
> > date() takes a Unix timestamp as its input.
> >
> > Unix timestamps are measured as number of seconds from Jan 1, 1970,
> > midnight, GMT, the birth of Disco.
> > [that last was a joke...]
> >
> > You are handing it a pre-formatted date-stamp in YYYYMMDDHHIISS format...
> >
> > You could do something like:
> > $t = '20070419162123';
> > $year = substr($t, 0, 4);
> > $month = substr($t, 4, 2);
> > $day = substr($t, 6, 2);
> > $hour = substr($t, 8, 2);
> > $minutes = substr($t, 10, 2);
> > $seconds = substr($t, 12, 2);
> > echo date(mktime($month, $day, $year, $hour, $minutes, $seconds));
> >
> > I suspect strtotime() *might* handle your input and give you a Unix
> > timestamp...
> >
> > I also suspect whatever you needed a Unix timestamp for in the first
> > place could have been achieved easier before you got painted into this
> > corner...

-- 
---
Børge
http://www.arivene.net
---

--- End Message ---
--- Begin Message ---
John Taylor-Johnston wrote:
> 
> It is actually a generated timestamp in MySQL.
> timestamp(14)
> Now what? I was hoping to avoid:
> |echo substr(|$mydata->timestamp|, 0, 8);

the simplest answer is actually yto make mySQL give you
the data in unix timestamp format in the first place:

SELECT UNIX_TIMESTAMP(my_field) AS my_timestamp FROM foo WHERE id=1;

> 
> John
> 
> |Richard Lynch wrote:
>> On Sun, April 22, 2007 1:05 am, John Taylor-Johnston wrote:
>>  
>>> $mydata->timestamp = "20070419162123";
>>>
>>> echo date('Y-m-d', $mydata->timestamp);
>>>
>>>
>>> result: 2038-01-18
>>>
>>> ?? What is wrong?? Should be 2007-04-19?
>>>     
>>
>> date() takes a Unix timestamp as its input.
>>
>> Unix timestamps are measured as number of seconds from Jan 1, 1970,
>> midnight, GMT, the birth of Disco.
>> [that last was a joke...]
>>
>> You are handing it a pre-formatted date-stamp in YYYYMMDDHHIISS format...
>>
>> You could do something like:
>> $t = '20070419162123';
>> $year = substr($t, 0, 4);
>> $month = substr($t, 4, 2);
>> $day = substr($t, 6, 2);
>> $hour = substr($t, 8, 2);
>> $minutes = substr($t, 10, 2);
>> $seconds = substr($t, 12, 2);
>> echo date(mktime($month, $day, $year, $hour, $minutes, $seconds));
>>
>> I suspect strtotime() *might* handle your input and give you a Unix
>> timestamp...
>>
>> I also suspect whatever you needed a Unix timestamp for in the first
>> place could have been achieved easier before you got painted into this
>> corner...
>>
>>   
> 

--- End Message ---
--- Begin Message ---
Richard Lynch wrote:
On Sat, April 21, 2007 10:56 pm, Myron Turner wrote:
trick for you.    You use the Perl script in the action attribute of
your form.  The Perl script saves the entire posted output to a file,
then it sends back a page which uses Javascript to redirect back to
the
php script, where you can process the file.  You send the file name
back
to the php script from the perl script in the query string of the url.

At that point, why not just have Perl call PHP?

Surely Perl can do something not unlike 'exec' or whatever to run any
shell script you want...

I sure wouldn't do another round trip to the browser and add JS into
the middle of this solution, if it's viable...

Wouldn't work for me, as I can't do Perl.

Perl could, could of course do the whole job. But since the Original Poster was (I assumed) not particularly familiar with Perl, I was essentially providing a Perl script to do the base essentials. So my hack would put him right back into PHP. If he execs from Perl to a PHP script to do the processing, then he would have to augment the Perl script to send back HTML to the browser, and if he can do that he can probably stick with the Perl altogether. Anyway, that was my reasoning.

--

_____________________
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

--- End Message ---
--- Begin Message ---
At 7:18 PM +0100 4/21/07, <[EMAIL PROTECTED]> wrote:
Hi sorry not really a php question.. but using it in a php script :)

I want to list the date and time a file was created so I want someting like..

Apr 21 18:57 monkey.txt

Ive been playing around with the LS options but I dont know what flags I need.
Closest I could get was..

ls  -g -o -t monkey.txt
-rw-r--r--  1 393 Apr 21 18:57 monkey.txt

What flags would I need to get rid of -rw-r--r--  1 393

Thanks


In html, try this:

Last updated <?php echo date("M j, Y",getlastmod());?>

Ad the time as you may.

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
Richard Lynch wrote:
> On Sat, April 21, 2007 1:18 pm, [EMAIL PROTECTED] wrote:
>> Hi sorry not really a php question.. but using it in a php script :)
>>
>> I want to list the date and time a file was created so I want someting
>> like..
>>
>> Apr 21 18:57 monkey.txt
>>
>> Ive been playing around with the LS options but I dont know what flags
>> I
>> need.
>> Closest I could get was..
>>
>> ls  -g -o -t monkey.txt
>> -rw-r--r--  1 393 Apr 21 18:57 monkey.txt
> 
> It may not be a PHP question, but here's a PHP answer:
> http://php.net/filectime
> 

Or for more info http://uk.php.net/manual/en/function.stat.php

Col

--- End Message ---
--- Begin Message ---
Alain Roger wrote:
Hi,

In my web application, end user is able to load images (png, jpeg, gif,..)
into database.
I would like to know how can i detect automatically the type of image (pnd,
jpeg,...) ?
i do not want to check the extension because this is easily faked... just by
renaming it.

Does it exist a technique for that ?

thanks a lot,


Is there anything wrong with just using $_FILES['upload_name']['type']?

--- End Message ---
--- Begin Message ---
On Sunday 22 April 2007 17:35, Jonathan wrote:
> Alain Roger wrote:
> > Hi,
> >
> > In my web application, end user is able to load images (png, jpeg,
> > gif,..) into database.
> > I would like to know how can i detect automatically the type of image
> > (pnd, jpeg,...) ?
> > i do not want to check the extension because this is easily faked...
> > just by
> > renaming it.
> >
> > Does it exist a technique for that ?
> >
> > thanks a lot,
>
> Is there anything wrong with just using $_FILES['upload_name']['type']?

read 8 lines further up

-- 
---
Børge
http://www.arivene.net
---

--- End Message ---
--- Begin Message ---
Jonathan wrote:
Alain Roger wrote:
Hi,

In my web application, end user is able to load images (png, jpeg, gif,..)
into database.
I would like to know how can i detect automatically the type of image (pnd,
jpeg,...) ?
i do not want to check the extension because this is easily faked... just by
renaming it.

Does it exist a technique for that ?

thanks a lot,


Is there anything wrong with just using $_FILES['upload_name']['type']?


$_FILES['upload_name']['type'] appears to believe the extension. Try it--upload a file with a misleading extension.

This same question was asked yesterday and the advice was to use
    string *mime_content_type* ( string filename)
That doesn't seem to get fooled very easily, though I suppose you could fool it if you went to the effort of, say, setting up a fake image header, when what you are sending is a time bomb.

M.


--

_____________________
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

--- End Message ---
--- Begin Message ---
On 4/22/07, Myron Turner <[EMAIL PROTECTED]> wrote:
Jonathan wrote:
> Alain Roger wrote:
>> Hi,
>>
>> In my web application, end user is able to load images (png, jpeg,
>> gif,..)
>> into database.
>> I would like to know how can i detect automatically the type of image
>> (pnd,
>> jpeg,...) ?
>> i do not want to check the extension because this is easily faked...
>> just by
>> renaming it.
>>
>> Does it exist a technique for that ?
>>
>> thanks a lot,
>>
>
> Is there anything wrong with just using $_FILES['upload_name']['type']?
>

$_FILES['upload_name']['type'] appears to believe the extension.  Try
it--upload a file with a misleading extension.

This same question was asked yesterday and the advice was to use
    string *mime_content_type* ( string filename)
That doesn't seem to get fooled very easily, though I suppose you could
fool it if you went to the effort of, say, setting up a fake image
header, when what you are sending is a time bomb.

M.

Yeah right, a time bomb with an image header :P
It should have an ELF header :) But then it would be detected by the
mime_content_type i guess.

Tijnema

--- End Message ---
--- Begin Message --- The proper way to handle special control PCRE characters like "\" is to use the hex [e.g., \x5C] value. Then you won't have a problem. The engine knows you want the the object treated as a character and an a control.

[EMAIL PROTECTED] wrote:
-- or maybe it's just the PCRE extension
-- or quite likely I have got something wrong

Hello members,
  I'm hoping you could enlighten me.

Using error_reporting = E_ALL | E_STRICT, I tested the following statements:

<?php
preg_match('#\\#','any-string'); => warning
preg_match('#\\\#','any-string');
preg_match('#\\\\#','any-string');
preg_match('#\\\\\#','any-string'); => warning
preg_match('#\\\\\\#','any-string'); => warning
preg_match('#\\\\\\\#','any-string');
?>

This seemed strange:
  warnings with 2 and 6 backlashes
  no warnings with 3, 7
  warning with 5 but not with 3 and 7.
The warning related of course to no matching delimeter '#' being found.

So I wrote a little test script (preg.php) to test up to 10 backslashes:

<?php
for($i=1; $i<=10; ++$i) {
    echo "\n---------------------------------\n";
    echo "Number of '\\' is $i \n";
    $bs = '#';
    $bs .=  str_repeat('\\',$i);
    $bs .= '#';
    echo 'Pattern is: ' . $bs . "\n";
    $php_errormsg = "";
    @preg_match($bs, "anystring") . "\n";
    if($php_errormsg != '')
        echo "error\n";
    else echo "ok\n";
}
?>

Here is the output:

$ php preg.php

---------------------------------
Number of '\' is 1
Pattern is: #\#
error

---------------------------------
Number of '\' is 2
Pattern is: #\\#
ok

---------------------------------
Number of '\' is 3
Pattern is: #\\\#
error

---------------------------------
Number of '\' is 4
Pattern is: #\\\\#
ok

---------------------------------
Number of '\' is 5
Pattern is: #\\\\\#
error

---------------------------------
Number of '\' is 6
Pattern is: #\\\\\\#
ok

---------------------------------
Number of '\' is 7
Pattern is: #\\\\\\\#
error

---------------------------------
Number of '\' is 8
Pattern is: #\\\\\\\\#
ok

---------------------------------
Number of '\' is 9
Pattern is: #\\\\\\\\\#
error

---------------------------------
Number of '\' is 10
Pattern is: #\\\\\\\\\\#
ok

End of output.

This agrees with my understanding of backslash escaping (I hope that's right) but now I can't understand why I got the results earlier (shown in my first script).

Many thanks.

--- End Message ---
--- Begin Message ---
Al wrote:
The proper way to handle special control PCRE characters like "\" is to use the hex [e.g., \x5C] value. Then you won't have a problem. The engine knows you want the the object treated as a character and an a control.

That works nicely, thank you.

--- End Message ---
--- Begin Message ---
Hi all how can i make my phpmyadmin run fast on windows ?  I installed 
phpmyadmin on a linux and windows machines, but the windows version runs 
(executes) too slow, i.e. it takes to long for a page to be loaded, while it 
take less that 3 secs for the linux version.  Both however run on the same 
system config.
   
  Cheers

       
---------------------------------
Ahhh...imagining that irresistible "new car" smell?
 Check outnew cars at Yahoo! Autos.

--- End Message ---
--- Begin Message ---
On Sunday 22 April 2007 22:33, Don Don wrote:
> Hi all how can i make my phpmyadmin run fast on windows ?

Why would you when you got linux up and running?

> I installed 
> phpmyadmin on a linux and windows machines, but the windows version runs
> (executes) too slow, i.e. it takes to long for a page to be loaded, while
> it take less that 3 secs for the linux version.  Both however run on the
> same system config.

It's not phpmyadmins fault, I've never had speed problem with/in windows in 
such manner. Of course that doesn't do much for suckiness

>
>   Cheers
>
>
> ---------------------------------
> Ahhh...imagining that irresistible "new car" smell?
>  Check outnew cars at Yahoo! Autos.

-- 
---
Børge
http://www.arivene.net
---

--- End Message ---
--- Begin Message ---
You say they both have the same config, so do you mean that they both
have the same version of PHP, same computer setup (Memory, CPU speed,
HDD speed), both running the same version of Apache, and that both are
running as either CGI or an apache module?

-Logan

-----Original Message-----
From: Don Don [mailto:[EMAIL PROTECTED] 
Sent: Sunday, April 22, 2007 4:34 PM
To: PHP List
Subject: [PHP] PhpMyAdmin slow on windows but fast on linux

Hi all how can i make my phpmyadmin run fast on windows ?  I installed
phpmyadmin on a linux and windows machines, but the windows version runs
(executes) too slow, i.e. it takes to long for a page to be loaded,
while it take less that 3 secs for the linux version.  Both however run
on the same system config.
   
  Cheers

       
---------------------------------
Ahhh...imagining that irresistible "new car" smell?
 Check outnew cars at Yahoo! Autos.

--- End Message ---
--- Begin Message ---
Hi

I'm would like to avoid PHP usages that are deprecated with regard to PHP 6. I would also like to code according to what is regarded as best practice. Are there any web resources that I can read to keep up to date?

For instance:
1) safe_mode is deprecated. (The PHP manual gives me the answer)

2) Are named accessor/mutator methods recommended over the __get() and __set() magic methods? (A best practice question).

Thanks

--- End Message ---
--- Begin Message ---
I get this error message when i try to check my site on localhost running 
IIS and PHP 5.1.2 :

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to 
allocate 24576 bytes) in ...

and it points to the line which is pure html code!
What could be the cause of this problem? 

--- End Message ---

Reply via email to