[PHP] crc check for JPEG file exists
hello is crc32() an acceptable way of managing whether a JPEG file exists (in a database or similar collection)? i mean doing a crc32() on the binary data of the JPEG file, and then check the database if there is already another entry with the same CRC. the database has relatively few images (some thousands). is there any chance of collision (two different JPEG images generating the same CRC) that is anywhere near likely, or is this extremely remote? advice would be appreciated. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] utf-8 in $_POST
the user agents in question are various mobile phones, which as you might guess are premature technology and have their own ways with things. here is an example posting from a Samsung D600 which insists on posting form data in UTF-8 even though i serve it ISO-8859-1 and it claims to support all character sets. [_POST] = Array ( [message] = Norwegian characters: øá ) [_SERVER] = Array ( [HTTP_ACCEPT_CHARSET] = * [CONTENT_TYPE] = application/x-www-form-urlencoded; charset=utf-8 [HTTP_USER_AGENT] = SAMSUNG-SGH-D600E/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0 ) i would consider switching to utf-8 if i knew how make the windows version of emacs work fine with utf-8 text files (and still work with iso-8859-1 files as well). On 08/01/2008, Per Jessen [EMAIL PROTECTED] wrote: Olav Mørkrid wrote: i specify iso-8859-1 in both header and body: meta http-equiv=Content-type content=text/html; charset=iso-8859-1/ form action=/ method=post accept-charset=iso-8859-1 Have you checked 1) what the webserver sends in the header and 2) what the browser actually uses? I'm pretty certain I've had issues where the meta tags were fine, but the server overrode me settings in the header. /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] utf-8 in $_POST
hello does php have any built-in functions to convert post data from whatever format it arrives in to whatever format i wish? example: i use iso-8859-1 internally, and even specify accept-charset=iso-8859-1 in my html, but some browsers (phones) send utf-8 anyway. do i have to manually check if CONTENT_TYPE says utf-8 and then convert the $_POST array elements one by one, or does php have any built-in functions to ease this? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] utf-8 in $_POST
i specify iso-8859-1 in both header and body: meta http-equiv=Content-type content=text/html; charset=iso-8859-1/ form action=/ method=post accept-charset=iso-8859-1 if two different people post the norwegian phrase Godt nytt år (happy new year), it may appear in the following variations: [CONTENT_TYPE] = application/x-www-form-urlencoded;charset=iso-8859-1 $_POST[input] = Godt nytt år [CONTENT_TYPE] = application/x-www-form-urlencoded;charset=utf-8 $_POST[input] = Godt nytt Ã¥r i was just wondering if php had some setting or function that would make it auto-convert $_POST data into one specific encoding. otherwise i seem forced to do something like this in the beginning of my php script: if(ereg(utf-8, $_SERVER[CONTENT_TYPE])) { foreach($_POST as $key = $value) $_POST[key] = convert_utf8_to_iso8859($value); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: how do i get a printout of original multipart post data
thanks, but that won't work. i need to see post data from other people out there, not my own data. still a mystery to me why php doesn't let developers see incoming raw data. On 01/12/2007, Dan [EMAIL PROTECTED] wrote: Olav Mørkrid [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] hello how can i get a raw and untouched printout of a multipart/form-data POST? i need this to analyze what certain user agents do wrong when uploading files. what happens is that php just fails to put files into $_FILES, and gives no way of seeing the original posting and exactly what is wrong with it. according to the manual, neither always_populate_raw_post_data nor php://input work for multipart/form-data. Go get Ethereal http://www.ethereal.com/ start the program, set which network card you want to use (you probably only have one), start capture. You'll now see all the packets going down the wire. Go ahead and do the post and you'll be able to see the post data. - Dan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] partial upload no file errors
hello under what EXACT circumstances does UPLOAD_ERR_PARTIAL and UPLOAD_ERR_NO_FILE occur? ...NO_FILE, does it happen ONLY if the user submits a form without choose a file to upload, or can this one also cover corrupt file data that php could not parse? ...PARTIAL, does it happen if the user presses STOP in his browser while uploading or he pulls out his network cable? if so, then he will never see any error message served upon this error... or does is it this one that covers corrupt mime data in the post? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how do i get a printout of original multipart post data
what is the thought behind php not providing access to original post data? this removes any chance of analyzing corrupt upload data, which is often the case with mobile browsers. can future versions of php please include a way of viewing raw server requests in full? On 26/11/2007, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: If you're with linux try netcat (nc) at listening mode. how can i get a raw and untouched printout of a multipart/form-data POST? i need this to analyze what certain user agents do wrong when uploading files. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] how do i get a printout of original multipart post data
hello how can i get a raw and untouched printout of a multipart/form-data POST? i need this to analyze what certain user agents do wrong when uploading files. what happens is that php just fails to put files into $_FILES, and gives no way of seeing the original posting and exactly what is wrong with it. according to the manual, neither always_populate_raw_post_data nor php://input work for multipart/form-data. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] what is my dns ip address
yeah but i assume this assumes you are on a unix machine and have administrator rights. it would be nice to be able to look up ip addresses swiftly and automatically on any machine and any operating system running php. On 03/09/07, Per Jessen [EMAIL PROTECTED] wrote: Olav Mørkrid wrote: the source of the problem is gethostbyaddr(). it seems to have a 4,5 second timeout, so some lookups time out after 4,5 seconds, while most of them are resolved in 0.1 second; a radically performance difference. You can change the timeout be amending the options statement in /etc/resolv.conf: options timeout: 2 (2 seconds). See 'man resolv.conf'. /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] what is my dns ip address
the source of the problem is gethostbyaddr(). it seems to have a 4,5 second timeout, so some lookups time out after 4,5 seconds, while most of them are resolved in 0.1 second; a radically performance difference. the user written gethostbyaddr_timeout() on the gethostbyaddr man page overcomes this problem, but unlike gethostbyaddr() requires a specific dns address, which seems unavailable from php at the moment. parsing nslookup and similar things seems like a workaround. where does one propose a dns_ip() function which returns the system's default dns ip address? or better yet, to add a timeout value to gethostbyaddr(), or in some other way ensure that lookups return quickly, whether they have an answer or not. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] what is my dns ip address
is there a function in php that will return the ip address of the dns server on the system? eg. $dns_ip = get_dns_ip_address(); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] isset($a-b) even if $a-b = null
how do i test if a property of a stdclass object is set, even if its value is null, similar to how array_key_exists() works for arrays. the following method fails: $a-b = null; if(isset($a-b)) echo yes; and property_exists() seems only to work for defined objects. hope someone can help. thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: isset($a-b) even if $a-b = null
the solution has been found. array_key_exists() can actually be used on objects, and yields the correct result. http://no.php.net/array_key_exists thanks to dordea cosmin for pointing this out. On 17/08/07, Olav Mørkrid [EMAIL PROTECTED] wrote: the test i need should give the following results: - FALSE when $a-b does not exist at all - TRUE when $a-b = null - TRUE when $a-b = any value empty() gives true for both $a-b = null and not setting any value, so that's no good. borokovs suggestion seems to miss the purpose. anyone else? On 17/08/07, Colin Guthrie [EMAIL PROTECTED] wrote: Olav Mørkrid wrote: how do i test if a property of a stdclass object is set, even if its value is null, similar to how array_key_exists() works for arrays. the following method fails: $a-b = null; if(isset($a-b)) echo yes; and property_exists() seems only to work for defined objects. hope someone can help. thanks! You can try: unset($a-b) Or change isset() to empty(). empty() catches more than isset() e.g. '' (empty string), false, 0 etc. are considered empty. Depending on your logic it can still be very useful. It is a language construct rather than a function so it's also efficient. Col -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: isset($a-b) even if $a-b = null
yes, but that assumes you have a defined class. if $a comes from mysql_fetch_object() for instance you have just a stdobject, and this method will produce an error. On 17/08/07, Michael Preslar [EMAIL PROTECTED] wrote: Found something. For class variables.. http://us.php.net/manual/en/function.property-exists.php class a { var $b; } if (property_exists('a','b')) { print yes\n; } On 8/17/07, Olav Mørkrid [EMAIL PROTECTED] wrote: the test i need should give the following results: - FALSE when $a-b does not exist at all - TRUE when $a-b = null - TRUE when $a-b = any value empty() gives true for both $a-b = null and not setting any value, so that's no good. borokovs suggestion seems to miss the purpose. anyone else? On 17/08/07, Colin Guthrie [EMAIL PROTECTED] wrote: Olav Mørkrid wrote: how do i test if a property of a stdclass object is set, even if its value is null, similar to how array_key_exists() works for arrays. the following method fails: $a-b = null; if(isset($a-b)) echo yes; and property_exists() seems only to work for defined objects. hope someone can help. thanks! You can try: unset($a-b) Or change isset() to empty(). empty() catches more than isset() e.g. '' (empty string), false, 0 etc. are considered empty. Depending on your logic it can still be very useful. It is a language construct rather than a function so it's also efficient. Col -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: isset($a-b) even if $a-b = null
the test i need should give the following results: - FALSE when $a-b does not exist at all - TRUE when $a-b = null - TRUE when $a-b = any value empty() gives true for both $a-b = null and not setting any value, so that's no good. borokovs suggestion seems to miss the purpose. anyone else? On 17/08/07, Colin Guthrie [EMAIL PROTECTED] wrote: Olav Mørkrid wrote: how do i test if a property of a stdclass object is set, even if its value is null, similar to how array_key_exists() works for arrays. the following method fails: $a-b = null; if(isset($a-b)) echo yes; and property_exists() seems only to work for defined objects. hope someone can help. thanks! You can try: unset($a-b) Or change isset() to empty(). empty() catches more than isset() e.g. '' (empty string), false, 0 etc. are considered empty. Depending on your logic it can still be very useful. It is a language construct rather than a function so it's also efficient. Col -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] repetition of tedious references
consider the following statement: $language = isset($_SERVER[HTTP_ACCEPT_LANGUAGE]) $_SERVER[HTTP_ACCEPT_LANGUAGE] != ? $_SERVER[HTTP_ACCEPT_LANGUAGE] : *; when using strings in arrays that may be non-existing or empty, you have to repeat the reference *three* times, which gets excessive and unreadable. is there any way to only have to write $_SERVER[HTTP_ACCEPT_LANGUAGE] only once? i know it's possible to supress is not set with @, but that just seems wrong in case there really is an error in the statement. i love php, but this is one of my pet peeves. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] repetition of tedious references
if the string is not set, you will get an undefined index error when calling isused(). that's just the problem. you can't reference an unset string without doing isset first, so putting isset inside the function is simply too late. On 18/07/07, C.R.Vegelin [EMAIL PROTECTED] wrote: Hi OLav, what about this ? $language = isused($_SERVER[HTTP_ACCEPT_LANGUAGE]); echo language is . $language; function isused($variable) { return isset($variable) $variable != ? $variable : *; } HTH, Cor - Original Message - From: Olav Mørkrid [EMAIL PROTECTED] To: PHP General List php-general@lists.php.net Sent: Wednesday, July 18, 2007 1:24 PM Subject: [PHP] repetition of tedious references consider the following statement: $language = isset($_SERVER[HTTP_ACCEPT_LANGUAGE]) $_SERVER[HTTP_ACCEPT_LANGUAGE] != ? $_SERVER[HTTP_ACCEPT_LANGUAGE] : *; when using strings in arrays that may be non-existing or empty, you have to repeat the reference *three* times, which gets excessive and unreadable. is there any way to only have to write $_SERVER[HTTP_ACCEPT_LANGUAGE] only once? i know it's possible to supress is not set with @, but that just seems wrong in case there really is an error in the statement. i love php, but this is one of my pet peeves. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] repetition of tedious references
rob, yes i thought of this, you could possible even do function magic($array, $name, $default=null ) { return isset($array[$name]) $array[$name] ? $array[$name] : $default; } $string = magic($_SERVER, HTTP_ACCEPT_LANGUAGE, *) however i wish php would have some built-in support to solve the issue. On 18/07/07, Robert Cummings [EMAIL PROTECTED] wrote: function getServerVar( $name, $default=null ) { return isset( $_SERVER[$name] ) ? $_SERVER[$name] : $default; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] repetition of tedious references
i didn't know about empty. thanks! do you have a link to this new php 6 ? : convention? it would be great if php 6 could have a solution for this. php is sweet when it's compact! On 18/07/07, Arpad Ray [EMAIL PROTECTED] wrote: You can use empty() to take one of them out, since 0 is presumably also not a desired input: $language = empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? * : $_SERVER['HTTP_ACCEPT_LANGUAGE']; There's a new ?: operator in PHP 6 which will make that even shorter, however unlike empty(), it currently throws a notice with unset operands. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] double output from trigger_error from command line
sorry. still get it twice. c:\php -r error_reporting(E_ALL ^ E_NOTICE); trigger_error(\hello\, E_USER_ERROR); PHP Fatal error: hello in Command line code on line 1 Fatal error: hello in Command line code on line 1 - if i do error_reporting(0) then i get NO lines at all. and if i do error_reporting(E_NOTICE) and then trigger_error(hello, E_NOTICE) i get two again. so there must be some setting beside error_reporting. On 17/07/07, Instruct ICC [EMAIL PROTECTED] wrote: My error_reporting level was at 2039 and I did not see the double messages. But I think you need to manipulate the error_reporting level. Maybe something like: php -r error_reporting(E_ALL ^ E_NOTICE); trigger_error(\hello\, E_USER_ERROR); Show me every report except E_NOTICE, and then trigger an E_USER_ERROR which says 'hello' Sorry, I didn't reply to the list the first time. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] double output from trigger_error from command line
if i do a trigger_error() when running php scripts from the command line, each error is echoed twice. this is annoying. does anyone know how to make each error display only once? c:\php -r trigger_error(\hello\); PHP Notice: hello in Command line code on line 1 Notice: hello in Command line code on line 1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] getting the next element of an associative array
chris for your suggestion to work, the internal array pointer of $array would first have to be set to point to the current element ($index). but how do you do this? this may seem like childs play, but i actually can't find any documented php function for this. it would be something like: array_set_internal_pointer($array, $index); On 12/07/07, Chris [EMAIL PROTECTED] wrote: Olav Mørkrid wrote: let's say we have the following associative array: $array = array( red = ferrari, yellow = volkswagen, green = mercedes, blue = volvo ); then we have a current index into the array: $index = yellow; $current = $array[$index]; now: how do i get the key of the next array element (in this case green)? $next = ? Funnily enough: $next = next($array); http://www.php.net/manual/en/function.next.php -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] getting the next element of an associative array
yep, a for loop is the fallback i use now. any reason why there isn't a built-in function for this? any plans for it in future versions of php? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] duration of mp3 file
http://arrozcru.no-ip.org/ffmpeg_builds/ On 11/07/07, Andrei [EMAIL PROTECTED] wrote: Or you could use ffmpeg executable to get details about the media file. You will have to parse the response of the executable. The only thing is that you must have exec function or an execution function available and ffmpeg installed. This is for linux machines tho... Don't know if ffmpeg is available for windows too. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] getting the next element of an associative array
let's say we have the following associative array: $array = array( red = ferrari, yellow = volkswagen, green = mercedes, blue = volvo ); then we have a current index into the array: $index = yellow; $current = $array[$index]; now: how do i get the key of the next array element (in this case green)? $next = ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] getting timestamp for first day of current week
what i need is that monday means monday this week, regardless of whether i ask on monday, tuesday, wednesday, thursday, friday, saturday or sunday. the way php works now, i have to something like this: if(date(l) == monday) $from = date(Y-m-d); // if today if monday, just give today's date else $from = date(Y-m-d, strtotime(last monday)); // when asking on tuesday thru sunday it would be nice if strtotime understood the form monday this week. On 04/07/07, Robert Cummings [EMAIL PROTECTED] wrote: On Wed, 2007-07-04 at 22:14 +0200, Olav Mørkrid wrote: On 03/07/07, Robert Cummings [EMAIL PROTECTED] wrote: If that's ALWAYS the case then it sounds like you have all the information you need to get the Monday you want :) what do you mean? php clearly makes a mistake in giving monday of the current week. I don't see how you figure clearly makes a mistake. For instance the following script illustrates a VERY clear behaviour that doesn't seem mistaken to me, it seems more like a design choice: ?php $days = array ( 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', ); foreach( $days as $day ) { echo date( 'Y-m-d', strtotime( $day ) ).' ('.$day.)\n; } ? You'll notice that it always presents the first such date from TODAY ONWARDS. With that in mind it is trivial to get the date YOU want. 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. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] getting timestamp for first day of current week
On 03/07/07, Robert Cummings [EMAIL PROTECTED] wrote: If that's ALWAYS the case then it sounds like you have all the information you need to get the Monday you want :) what do you mean? php clearly makes a mistake in giving monday of the current week. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] getting timestamp for first day of current week
hello how do i get the TIMESTAMP for the FIRST DAY of the CURRENT WEEK (ie. monday 00:00:00)? i tried using strtotime(monday), but: - when i use it on a monday, i get monday THIS WEEK - when i use it on tuesday thru sunday, i get monday NEXT WEEK i tried last monday, monday this week, this monday, etc. but nothing helps. this code proves the issue (2 july is a monday, 8 july is a sunday) for($d=2; $d=8; $d++) { $time = strtotime($d july 2007); $date = date(Y-m-d, strtotime(monday, $time)); echo $datebr/\n; } is this a bug, or a locale issue? at any rate, how do i get monday 00:00:00? thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php