Re: [PHP] Best way to create an image with flowing text?
On 16 June 2011 23:59, Brian Dunning br...@briandunning.com wrote: Hey all - I need to create PNG images with transparent backgrounds that contain text. The text will come from four fields in a database, and needs to be centered, and text wrapped. The fields are going to be of varying lengths, so each block of text (which will be shown in a different font size) will flow onto an unknown number of lines, and I want to start the next line right below, wherever it is. Unfortunately I have come up against some restrictions. - I will not be able to use ImageMagick. - I have Ghostscript, but only version 7.07. - The server is Red Hat 4.x with PHP 5.2 and installing new software is unlikely. Can anyone suggest a tool to make this easiest? :-( - Brian Do you have the image extension loaded? A LONG time ago (nearly 7 years ago - just when I first started using PHP - so please forgive the code), I built a script to take words and scale them to fill a box. The technique of getting the size of the text could still be useful here. It was in response to a question on Experts Exchange (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_21113446.html#a11972605) The code is awful by my current standards. But it worked. So there must be something in that. I'll send you the code directly as, frankly, it is embarrassing to see today. -- Richard Quadling Twitter : EE : Zend : PHPDoc @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Best way to create an image with flowing text?
Hey all - I need to create PNG images with transparent backgrounds that contain text. The text will come from four fields in a database, and needs to be centered, and text wrapped. The fields are going to be of varying lengths, so each block of text (which will be shown in a different font size) will flow onto an unknown number of lines, and I want to start the next line right below, wherever it is. Unfortunately I have come up against some restrictions. - I will not be able to use ImageMagick. - I have Ghostscript, but only version 7.07. - The server is Red Hat 4.x with PHP 5.2 and installing new software is unlikely. Can anyone suggest a tool to make this easiest? :-( - Brian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to determine mime type of file these days?
Robert P. J. Day wrote: i realize it sounds trivial but the online info is annoyingly recursive. there's mime_content_type(), but it's officially deprecated. On the manual page there is a reference to the Fileinfo PECL extension: http://php/manual/en/ref.fileinfo.php -- Per Jessen, Zürich (9.1°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to determine mime type of file these days?
At 8:52 AM +0100 3/18/10, Per Jessen wrote: Robert P. J. Day wrote: i realize it sounds trivial but the online info is annoyingly recursive. there's mime_content_type(), but it's officially deprecated. On the manual page there is a reference to the Fileinfo PECL extension: http://php/manual/en/ref.fileinfo.php Broken. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to determine mime type of file these days?
tedd wrote: At 8:52 AM +0100 3/18/10, Per Jessen wrote: Robert P. J. Day wrote: i realize it sounds trivial but the online info is annoyingly recursive. there's mime_content_type(), but it's officially deprecated. On the manual page there is a reference to the Fileinfo PECL extension: http://php/manual/en/ref.fileinfo.php Broken. Sorry, that was a link to my local copy. http://php.net/manual/en/ref.fileinfo.php -- Per Jessen, Zürich (14.8°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to set up an include path for a multi-level project?
On Tue, 16 Mar 2010, John Black wrote: On 03/16/2010 06:57 PM, Robert P. J. Day wrote: i have a project (let's call it proj) which lives in the proj directory and which contains several subdirs, some of which might contain their own subdirs and so on. some of those subdirs might contain utility classes that i want to include or require elsewhere, so i want to be able to just: require 'util.php'; and have the PHP include path do the right thing. right now, it's ugly, as in, having PHP files that do: require '../../proj/util.php'; meaning every single file that wants to include another proj-related file has to know its relative position in the proj hierarchy. barf. I used to use auto detecting absolute paths but switched to relative paths when a client decided to switch his hosting company, I *think* it was GoDaddy. They required relative paths when using the shared SSL server or the browser would throw errors. It is really not bad as long a you keep your directory structure consistent. I have never received a bug report because of an include path issue. It also does not matter where the root directory of the app is located since everything is relative anyway. There is also no need for the user to configure anything because of the relative paths. So I just set $include = './include/abc/def/' at the top of the executing php page and use it further down. You make $include a global or simply pass $include to functions or classes when they need to include files. I use the later approach. As I said I never had a problem with it, it just requires consistency. i'm not entirely sure what you're suggesting here, but i don't think it will work for me as one of the things i want to do is set up a test directory, inside which i might have subdirectories with more test routines, so i can't guarantee *anyone's* position relative to the top of the proj directory. i might even want to write PHP scripts and place them quite some distance from the proj directory but still want to include utility scripts from the proj directory. based on how i've done this with shell and makefile-based projects in the past, the easiest solution seemed to be to simply demand that users set a single environment variable identifying the location of the proj directory, and base everything off of that by extending the include path. at that point, everything falls into place and all include/require references work relative to the top of the proj tree. i think that's the direction i'm going to go, unless someone has a compelling reason not to. thanks. rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] best way to set up an include path for a multi-level project?
From: Robert P. J. Day On Tue, 16 Mar 2010, John Black wrote: On 03/16/2010 06:57 PM, Robert P. J. Day wrote: i have a project (let's call it proj) which lives in the proj directory and which contains several subdirs, some of which might contain their own subdirs and so on. some of those subdirs might contain utility classes that i want to include or require elsewhere, so i want to be able to just: require 'util.php'; and have the PHP include path do the right thing. right now, it's ugly, as in, having PHP files that do: require '../../proj/util.php'; meaning every single file that wants to include another proj-related file has to know its relative position in the proj hierarchy. barf. I used to use auto detecting absolute paths but switched to relative paths when a client decided to switch his hosting company, I *think* it was GoDaddy. They required relative paths when using the shared SSL server or the browser would throw errors. It is really not bad as long a you keep your directory structure consistent. I have never received a bug report because of an include path issue. It also does not matter where the root directory of the app is located since everything is relative anyway. There is also no need for the user to configure anything because of the relative paths. So I just set $include = './include/abc/def/' at the top of the executing php page and use it further down. You make $include a global or simply pass $include to functions or classes when they need to include files. I use the later approach. As I said I never had a problem with it, it just requires consistency. i'm not entirely sure what you're suggesting here, but i don't think it will work for me as one of the things i want to do is set up a test directory, inside which i might have subdirectories with more test routines, so i can't guarantee *anyone's* position relative to the top of the proj directory. i might even want to write PHP scripts and place them quite some distance from the proj directory but still want to include utility scripts from the proj directory. based on how i've done this with shell and makefile-based projects in the past, the easiest solution seemed to be to simply demand that users set a single environment variable identifying the location of the proj directory, and base everything off of that by extending the include path. at that point, everything falls into place and all include/require references work relative to the top of the proj tree. i think that's the direction i'm going to go, unless someone has a compelling reason not to. thanks. IOW, you want to point into the first project's test directory from other projects when you can't know the relative paths between those projects? I suspect you will have to manage that on a machine by machine basis, unless you can convince the entire development team to create a common directory structure that encompasses all projects. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] best way to set up an include path for a multi-level project?
On Wed, 17 Mar 2010, Bob McConnell wrote: ... snip ... IOW, you want to point into the first project's test directory from other projects when you can't know the relative paths between those projects? I suspect you will have to manage that on a machine by machine basis, unless you can convince the entire development team to create a common directory structure that encompasses all projects. let me emphasize that the layout of the entire proj directory will be consistent across all users and all machines since it will represent a single SVN checkout, so that's not an issue. of course, anyone will be free to check it out anywhere they want but once they do, its structure will be the same across all checkouts. that's why i think the easiest solution is to define a single environment variable (say, PROJ_DIR) that anyone can set depending on where they do the checkout, the PHP code itself will (somehow) initially consult that variable, and all inclusion from then on will be based on that. piece of cake, no? in fact, developers are free to do more than one checkout, work on them independently, and change PROJ_DIR depending on which one they want to pick up for their code. does that more clearly explain what i think the right approach is? rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] best way to set up an include path for a multi-level project?
On Wed, 17 Mar 2010, Bob McConnell wrote: I suspect you will have to manage that on a machine by machine basis, unless you can convince the entire development team to create a common directory structure that encompasses all projects. i'm not sure what you mean by the above. while that single project (that others might want to take advantage of) will have to have a uniform and consistent layout for everyone, i don't see that that will enforce any sort of uniformity on *other* projects that might want to take advantage of it. or am i misunderstanding you? rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] best way to set up an include path for a multi-level project?
let me emphasize that the layout of the entire proj directory will be consistent across all users and all machines since it will represent a single SVN checkout, so that's not an issue. of course, anyone will be free to check it out anywhere they want but once they do, its structure will be the same across all checkouts. The problem of an easy include path also came up in our project. The solution was to create a Bootstrap class, that sets the include path as follows: private function __construct() { // Set the include path, where to look for included files. // This is important so as to make pointing to the included files much easier, // and to avoid tortuous path references. $this-bibledit_root_folder = dirname (dirname(__FILE__)); $include_path = get_include_path () . : . $this-bibledit_root_folder; set_include_path ($include_path); ini_set('include_path', $include_path); } The central issue in the above is to use the __FILE__ variable as the starting point for the include path. Since the bootstrap.php is in a known location in the directory tree, we can always deduce a known include path from that. After that, each php file in each directory was set to include this bootstrap.php, in various forms, depending on where this php file was located in the directory tree: require_once (../bootstrap/bootstrap.php); or: require_once (../../bootstrap/bootstrap.php); or require_once (bootstrap/bootstrap.php); That way the include path got set bootstrap.php. It works well. Teus. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] best way to set up an include path for a multi-level project?
i have a project (let's call it proj) which lives in the proj directory and which contains several subdirs, some of which might contain their own subdirs and so on. some of those subdirs might contain utility classes that i want to include or require elsewhere, so i want to be able to just: require 'util.php'; and have the PHP include path do the right thing. right now, it's ugly, as in, having PHP files that do: require '../../proj/util.php'; meaning every single file that wants to include another proj-related file has to know its relative position in the proj hierarchy. barf. based on my experience with shell and makefile-based projects, my preference would be that anyone who checks out a copy of the project can check it out anywhere they want, then they need to set the single shell environment variable, say PROJ_DIR, to the top-level directory location, say: $ export PROJ_DIR=/home/rpjday/php/things/proj i would then make sure that env vars are available to PHP scripts via /etc/php.ini: variables_order = EGPCS ^ and all PHP scripts would start off with something like: set_include_path(get_include_path() . PATH_SEPARATOR . getenv('PROJ_DIR')); at that point (and correct me if i'm wrong), all subsequent includes or requires would simply need to reflect the location of the file relative to its PROJ_DIR location (barring any weird conflicts with system files having the same name, of course). does that sound about right? is there a standard way to do this? that is, to have a sizable PHP hierarchy and allow any files within that hierarchy to include others conveniently without having to hardcode directory names. requiring users to simply set a single env var has always worked for me. is that what others do to solve this? thanks. rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to set up an include path for a multi-level project?
On 03/16/2010 06:57 PM, Robert P. J. Day wrote: i have a project (let's call it proj) which lives in the proj directory and which contains several subdirs, some of which might contain their own subdirs and so on. some of those subdirs might contain utility classes that i want to include or require elsewhere, so i want to be able to just: require 'util.php'; and have the PHP include path do the right thing. right now, it's ugly, as in, having PHP files that do: require '../../proj/util.php'; meaning every single file that wants to include another proj-related file has to know its relative position in the proj hierarchy. barf. I used to use auto detecting absolute paths but switched to relative paths when a client decided to switch his hosting company, I *think* it was GoDaddy. They required relative paths when using the shared SSL server or the browser would throw errors. It is really not bad as long a you keep your directory structure consistent. I have never received a bug report because of an include path issue. It also does not matter where the root directory of the app is located since everything is relative anyway. There is also no need for the user to configure anything because of the relative paths. So I just set $include = './include/abc/def/' at the top of the executing php page and use it further down. You make $include a global or simply pass $include to functions or classes when they need to include files. I use the later approach. As I said I never had a problem with it, it just requires consistency. -- John Eine der erstaunlichsten Erscheinungen ist, daß man sich einbildet, von abhängigen Menschen unabhängige Meinungen erwarten zu dürfen. [Sigmund Graff] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to set up an include path for a multi-level project?
On 03/16/2010 08:50 PM, John Black wrote: So I just set $include = './include/abc/def/' at the top of the correction, I set $include to the relative path of the include directory and then use it like this: $include = '../../include/'; require $include.'abc/file1.php'; require_once $include.'abc/def/file2.php'; require_once $include.'file3.php'; Still works the same way but since all my include files are in include or some sub directory of it this works perfect. -- John Vorurteil ist das Kind von Ignoranz. [William Hazlitt] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to set up an include path for a multi-level project?
On Tue, Mar 16, 2010 at 1:57 PM, Robert P. J. Day rpj...@crashcourse.ca wrote: and all PHP scripts would start off with something like: set_include_path(get_include_path() . PATH_SEPARATOR . getenv('PROJ_DIR')); just utilize include_path directive in php.ini -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to set up an include path for a multi-level project?
On Tue, Mar 16, 2010 at 9:48 PM, Ryan Sun ryansu...@gmail.com wrote: just utilize include_path directive in php.ini yea, or via ini_set('include_path', ); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to determine (MIME) content type of a stream ofbytes?
Robert P. J. Day wrote: On Mon, 8 Mar 2010, Ashley Sheridan wrote: What about writing the first n bytes to a file and then passing that to the command line? I'm assuming a Linux server here, but it should do the trick. gah! i was hoping for something that wouldn't make me want to gouge out my eyes with a soup spoon. :-) Maybe slightly less painfull, you can always write your own 'mimemagic' detection method. The magic.mime file is relatively easy to parse. This is the route we took some years ago to make our mime detection OS independant. We've made a php script which parses the mime.types file and the magic.mime file and it generates a php module which uses that information to figure out the correct mimetype. The resulting php module has a large array, which looks like this: ... $mimemagic_data[0][4][\0\0\1\273]=video/mpeg; $mimemagic_data[0][4][\0\0\2\0]=application/x-123; $mimemagic_data[0][4][\0\0\32\0]=application/x-123; $mimemagic_data[0][4][\0\6\25\141]=application/x-dbm; $mimemagic_data[0][4][\101\104\111\106]=audio/X-HX-AAC-ADIF; $mimemagic_data[0][4][\103\120\103\262]=image/x-cpi; ... with the first key as the offset to start, the next key is the length of the snippet to check (I guess that could have been skipped...) and the final key is the exact string to match. The magic.mime file is no magic bullet though, there are occasions when it won't match with a file, but that's usually with more complex types like microsoft office documents, not with images. If you're interested, the mimemagic module can be found here: http://svn.muze.nl/trunk/lib/modules/mod_mimemagic.php?revision=4299root=ariadne-php5 And the builder script (which you should run on a unix system with magic.mime and mime.types file) is here: http://svn.muze.nl/trunk/bin/utils/build_mimemagic_script.php?revision=4299root=ariadne-php5 Hope this helps, Auke van Slooten Muze -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] best way to determine (MIME) content type of a stream of bytes?
hi, i'm interested in the most comprehensive way to determine the content type of a stream of bytes that's been uploaded to a PHP script? assuming that the bytes are uploaded simply via a POST parameter, i can see that there are a couple ways to do it: * getimagesize() * FileInfo i've been doing some testing this morning and a few video formats handed to FileInfo come back as application/octet-stream which isn't particularly informative. and i want to support as many different formats of image, audio and video as possible. so ... what's the best way? oh, by the way, when i used fileinfo, i didn't bother handing over a magic file. i'm starting to think that would make a difference. and is there a noticeable advantage to upgrading to PHP 5.3 since the server (centos 5.4) is currently running only PHP 5.1.6. thanks. rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to determine (MIME) content type of a stream of bytes?
On Mon, 2010-03-08 at 10:57 -0500, Robert P. J. Day wrote: hi, i'm interested in the most comprehensive way to determine the content type of a stream of bytes that's been uploaded to a PHP script? assuming that the bytes are uploaded simply via a POST parameter, i can see that there are a couple ways to do it: * getimagesize() * FileInfo i've been doing some testing this morning and a few video formats handed to FileInfo come back as application/octet-stream which isn't particularly informative. and i want to support as many different formats of image, audio and video as possible. so ... what's the best way? oh, by the way, when i used fileinfo, i didn't bother handing over a magic file. i'm starting to think that would make a difference. and is there a noticeable advantage to upgrading to PHP 5.3 since the server (centos 5.4) is currently running only PHP 5.1.6. thanks. rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday If you're wanting to grab details about a clip, what about using mplayer for dealing with video clips. It has more than a few command line options that can return various levels of detail about a media file. You could use the extension of the clip as a hint about what way you can determine a files exact type. So, if a file came in with a jpg, png or gif extension, you could use GD functions to determine if it's really an image. If it's a .avi, .mpg, .mp4, .mp3, .ogg, you could use mplayer to deal with it. This does seem to ba a bit of an area where PHP is lacking. Even the manual pages are cryptic. It seems to suggest that the Mime functions which we should use in-place of deprecated ones themselves rely on those same deprecated functions! Having said that, I've had good results from using file -f filename on Linux, which is using version 5.03 on my system. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] best way to determine (MIME) content type of a stream of bytes?
On Mon, 8 Mar 2010, Ashley Sheridan wrote: On Mon, 2010-03-08 at 10:57 -0500, Robert P. J. Day wrote: hi, i'm interested in the most comprehensive way to determine the content type of a stream of bytes that's been uploaded to a PHP script? assuming that the bytes are uploaded simply via a POST parameter, i can see that there are a couple ways to do it: * getimagesize() * FileInfo i've been doing some testing this morning and a few video formats handed to FileInfo come back as application/octet-stream which isn't particularly informative. and i want to support as many different formats of image, audio and video as possible. so ... what's the best way? oh, by the way, when i used fileinfo, i didn't bother handing over a magic file. i'm starting to think that would make a difference. and is there a noticeable advantage to upgrading to PHP 5.3 since the server (centos 5.4) is currently running only PHP 5.1.6. thanks. If you're wanting to grab details about a clip, what about using mplayer for dealing with video clips. It has more than a few command line options that can return various levels of detail about a media file. You could use the extension of the clip as a hint about what way you can determine a files exact type. So, if a file came in with a jpg, png or gif extension, you could use GD functions to determine if it's really an image. If it's a .avi, .mpg, .mp4, .mp3, .ogg, you could use mplayer to deal with it. in order to make life as difficult as possible, all i can assume is an incoming stream of bytes. i will have no idea where it came from, or its original file name. all of the mime/type identification has to be done by the PHP script on the server end, based solely on the content. (i'm fairly sure that means a magic file will have to be involved.) This does seem to ba a bit of an area where PHP is lacking. Even the manual pages are cryptic. It seems to suggest that the Mime functions which we should use in-place of deprecated ones themselves rely on those same deprecated functions! i have noticed that. the mime_content_type() function looked like a good candidate but it's marked as deprecated. the best option appears to be the Fileinfo stuff. rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to determine (MIME) content type of a stream of bytes?
On Mon, 2010-03-08 at 11:33 -0500, Robert P. J. Day wrote: On Mon, 8 Mar 2010, Ashley Sheridan wrote: On Mon, 2010-03-08 at 10:57 -0500, Robert P. J. Day wrote: hi, i'm interested in the most comprehensive way to determine the content type of a stream of bytes that's been uploaded to a PHP script? assuming that the bytes are uploaded simply via a POST parameter, i can see that there are a couple ways to do it: * getimagesize() * FileInfo i've been doing some testing this morning and a few video formats handed to FileInfo come back as application/octet-stream which isn't particularly informative. and i want to support as many different formats of image, audio and video as possible. so ... what's the best way? oh, by the way, when i used fileinfo, i didn't bother handing over a magic file. i'm starting to think that would make a difference. and is there a noticeable advantage to upgrading to PHP 5.3 since the server (centos 5.4) is currently running only PHP 5.1.6. thanks. If you're wanting to grab details about a clip, what about using mplayer for dealing with video clips. It has more than a few command line options that can return various levels of detail about a media file. You could use the extension of the clip as a hint about what way you can determine a files exact type. So, if a file came in with a jpg, png or gif extension, you could use GD functions to determine if it's really an image. If it's a .avi, .mpg, .mp4, .mp3, .ogg, you could use mplayer to deal with it. in order to make life as difficult as possible, all i can assume is an incoming stream of bytes. i will have no idea where it came from, or its original file name. all of the mime/type identification has to be done by the PHP script on the server end, based solely on the content. (i'm fairly sure that means a magic file will have to be involved.) This does seem to ba a bit of an area where PHP is lacking. Even the manual pages are cryptic. It seems to suggest that the Mime functions which we should use in-place of deprecated ones themselves rely on those same deprecated functions! i have noticed that. the mime_content_type() function looked like a good candidate but it's marked as deprecated. the best option appears to be the Fileinfo stuff. rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday What about writing the first n bytes to a file and then passing that to the command line? I'm assuming a Linux server here, but it should do the trick. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] best way to determine (MIME) content type of a stream of bytes?
On Mon, 8 Mar 2010, Ashley Sheridan wrote: What about writing the first n bytes to a file and then passing that to the command line? I'm assuming a Linux server here, but it should do the trick. gah! i was hoping for something that wouldn't make me want to gouge out my eyes with a soup spoon. :-) rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to determine (MIME) content type of a stream of bytes?
On Mon, 2010-03-08 at 11:37 -0500, Robert P. J. Day wrote: On Mon, 8 Mar 2010, Ashley Sheridan wrote: What about writing the first n bytes to a file and then passing that to the command line? I'm assuming a Linux server here, but it should do the trick. gah! i was hoping for something that wouldn't make me want to gouge out my eyes with a soup spoon. :-) rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday Lol, that's about the easiest way I can think of doing it reliably! Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Best way to read first 20 characters of a string?
On Wed, Dec 2, 2009 at 10:11, Chris Payne chris_pa...@danmangames.com wrote: Hi everyone, I'm pulling data from a mysql database, but need only the first 20 characters of each string for a short description, what is the best method to just grab the first 20 characters from a string regardless of whether they are letters or numbers? ?php $chars = substr($yourInput,0,20); ? -- /Daniel P. Brown daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ Looking for hosting or dedicated servers? Ask me how we can fit your budget! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Best way to test for form submission?
This question might give away the fact that I am a php noob, but I am looking for the best way to test for form submission in PHP. I know in Perl this can be done with if (param) but I don't know if that will work with PHP. I have read the Learning PHP 5 book and the only thing that was mentioned in the book was the use of something like this print pHello .$_POST['username']./p; I'm sure that this is not the best/recommended way to do this but I'm hoping someone here will point me in the right direction. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?
Govinda wrote: I want something that will work for calling an include from any file that lives n levels deep. That's where you have to define a variable (or constant) that tells the system where the web root is located, and then use that to determine where you are in relation to that. For example: ?php function relate_path($me,$root = '/home/pilotpig/public_html') { if(preg_match('/\/.*\.[a-z0-9]{2,5}$/Ui',$me)) { // If a file with extension 2-5 alphanum chars $me = dirname($me); // Strip the filename // Then loop through the correct number of times. for($i=0;$i(substr_count($me,'/') - substr_count($root,'/'));$i++) { $me = dirname($me); } return $me; // Returns the resulting path. } return false; // If we were unable to get the path. } /* Then use it as follows, presuming this file is named /home/user/public_html/web/home.php */ if(($path = relate_path(__FILE__)) !== false) { include($path.'/include/config.php'); } else { // Handle the error for the incorrect inclusion attempt. } ? Voila! Also, what is the difference between a path that starts with /, versus the same path but that does not have that leading /, or that same path but prefixed with ./? I.e., this: /somepath/includes/file.php is a true (absolute) path. versus this: somepath/includes/file.php is a relative path from wherever the file is called. versus this: ./somepath/includes/file.php is a relative path from the CWD/PWD (Current Working Directory/Present Working Directory). P.S. - The function is untested, just rattled off from my brain while I cook dinner, so if it doesn't work, at least you should get the gist of where I'm going but try it anyway. ;-P Dan I love to see smart hacks in action! ..and I believe I get what you are doing. I am just amazed that there is not a SIMPLE (one-liner) reliable way of just saying document root without a complex function like that. $documentRoot = '/srv/website/www' Unless you change your site configuration option, that is both concise and easy to understand when you (or someone else) reads the code 5 months from now. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?
On Sun, 5 Jul 2009 14:33:07 -0600 Govinda govinda.webdnat...@gmail.com wrote: I am confusing myself reading the docs just now. i.e.: include_path basename() and dirname() I had thought from many months ago that ?php include '/somedir/somefile.php'; ? would include somefile.php living in somedir regardless from where in the site structure I am calling it. Now it does not seem to be doing that. What is the safest (portable) way to properly build an include path *regardless* from where in my site I am calling the include? If I understand right I can put includes in a dir/ specified by the include_path setting, but I also want to know how to do this from just within the root of my virtual server. Like Michael said there is more than one way to deal with this. I personally prefer to use this: require_once ($_SERVER['DOCUMENT_ROOT'] . /incl/myfile.php); Unless the file needs to be kept outside of where the webserver serves files. -Govinda -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Mange venlige hilsner/Best regards Kim Naim Lesmer Programmer/Unix systemadministrator Web: www.bitflop.com E-mail : k...@bitflop.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?
On Jul 5, 2009, at 4:42 PM, Kim N. Lesmer wrote: Like Michael said there is more than one way to deal with this. I personally prefer to use this: require_once ($_SERVER['DOCUMENT_ROOT'] . /incl/myfile.php); Unless the file needs to be kept outside of where the webserver serves files. Kim, this is exactly what I was looking for. I had been over $_SERVER in the docs.. but somehow missed that basic obvious param. Thanks! Sudeer, Shawn, Michael, your efforts were not wasted either. I absorbed from you all and came up with: define('MY_DOC_ROOT', $_SERVER['DOCUMENT_ROOT']); set_include_path(MY_DOC_ROOT . PATH_SEPARATOR . get_include_path()); include 'MY_php_functions.inc'; which I call with: include $_SERVER['DOCUMENT_ROOT'] . '/MY_inc_php/incsInAllPages.inc'; really basic stuff.. humbling for me, coming from other languages/ environements where I was more expert. ..lucky me this is such a generous and compassionate group of people here. Thanks again -Govinda -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?
On Mon, Jul 6, 2009 at 11:04, Govindagovinda.webdnat...@gmail.com wrote: Kim, this is exactly what I was looking for. I had been over $_SERVER in the docs.. but somehow missed that basic obvious param. Thanks! And now I'll throw a monkey wrench into the gears and tell you that, yes, it works, but don't always rely on it. The path translated to/from the web server may not be the real path. And while you could do your translation with realpath(), instead you should look into: ?php include(dirname(dirname(__FILE__)).'/include/file.php'); ? The example above uses the always-on reserved constant __FILE__ for the file in which it's written, regardless of how it's accessed (as an include, etc.). So consider the following: /home/user/public_html/index.php /home/user/public_html/web/home.php /home/user/public_html/templates/body.tpl.php /home/user/public_html/include/file.php In the example above, imagine that you access 'index.php', which includes 'home.php', which - in turn - includes 'body.tpl.php' and 'file.php'. Using $_SERVER data will use the information given to it by the webserver at the point of the call: in this case, from /home/user/public_html/index.php. As such, the include path will be relative to that. So if you're including a file in ./web/home.php, you will need to hard-code the adjustment to account for the difference. Conversely, using the code example from above (and building upon it), we know that __FILE__ remains static regardless of the point of the call. Thus, it's a better and more reliable method, and is usable even if $_SERVER data is not available to the script. With this in mind, it should be quite simple to understand how the following should work: ?php // My Name: /home/user/public_html/web/home.php $file_to_include = dirname(dirname(__FILE__)).'/include/file.php'; if(file_exists($file_to_include) is_readable($file_to_include)) { include($file_to_include); } else { // Do your error handling here. } ? but to each his/her own! ;-P -- /Daniel P. Brown daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ Check out our great hosting and dedicated server deals at http://twitter.com/pilotpig -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?
On Mon, Jul 6, 2009 at 8:24 AM, Daniel Brownparas...@gmail.com wrote: Conversely, using the code example from above (and building upon it), we know that __FILE__ remains static regardless of the point of the call. Thus, it's a better and more reliable method, and is usable even if $_SERVER data is not available to the script. +1 - i use dirname(__FILE__) everywhere. Rasmus said you can just use ./includes/foo.php, why have an extra function call (the dirname) but i tried that on one of my setups and what is odd is it couldn't find the files from the forced relative paths which should work just fine. there could have been other weird voodoo going on too, but i know for a fact dirname(__FILE__) has been reliable and the best part is it does not require $_SERVER. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?
On Jul 6, 2009, at 9:24 AM, Daniel Brown wrote: On Mon, Jul 6, 2009 at 11:04, Govindagovinda.webdnat...@gmail.com wrote: Kim, this is exactly what I was looking for. I had been over $_SERVER in the docs.. but somehow missed that basic obvious param. Thanks! And now I'll throw a monkey wrench into the gears and tell you that, yes, it works, but don't always rely on it. The path translated to/from the web server may not be the real path. And while you could do your translation with realpath(), instead you should look into: ?php include(dirname(dirname(__FILE__)).'/include/ file.php'); ? The example above uses the always-on reserved constant __FILE__ for the file in which it's written, regardless of how it's accessed (as an include, etc.). So consider the following: /home/user/public_html/index.php /home/user/public_html/web/home.php /home/user/public_html/templates/body.tpl.php /home/user/public_html/include/file.php In the example above, imagine that you access 'index.php', which includes 'home.php', which - in turn - includes 'body.tpl.php' and 'file.php'. Using $_SERVER data will use the information given to it by the webserver at the point of the call: in this case, from /home/user/public_html/index.php. As such, the include path will be relative to that. So if you're including a file in ./web/home.php, you will need to hard-code the adjustment to account for the difference. Conversely, using the code example from above (and building upon it), we know that __FILE__ remains static regardless of the point of the call. Thus, it's a better and more reliable method, and is usable even if $_SERVER data is not available to the script. With this in mind, it should be quite simple to understand how the following should work: ?php // My Name: /home/user/public_html/web/home.php $file_to_include = dirname(dirname(__FILE__)).'/include/file.php'; if(file_exists($file_to_include) is_readable($file_to_include)) { include($file_to_include); } else { // Do your error handling here. } ? but to each his/her own! ;-P Michael and Dan this is great, but then I still do not have a solution that will work for any level deep of dir/ . I.e. this- dirname(dirname(__FILE__)) gives the correct first part of the path to document root like $_SERVER['DOCUMENT_ROOT'] does only when called from a file that is 2 levels deep. I want something that will work for calling an include from any file that lives n levels deep. Isn't there anything reliable that effectively says, from document root?? I do not really understand why $_SERVER['DOCUMENT_ROOT'] should return the right data at one time and not at another. (?) -- Also, what is the difference between a path that starts with /, versus the same path but that does not have that leading /, or that same path but prefixed with ./? I.e., this: /somepath/includes/file.php versus this: somepath/includes/file.php versus this: ./somepath/includes/file.php (../ I know) -G
Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?
On Mon, 6 Jul 2009 16:16:55 -0600 Govinda govinda.webdnat...@gmail.com wrote: I do not really understand why $_SERVER['DOCUMENT_ROOT'] should return the right data at one time and not at another. (?) In general it will always provide the right data, but as the manual says: The entries in this array ($_SERVER) are created by the web server. There is no guarantee that every web server will provide any of these; servers may omit some. The problem could arise if the script is transfered unto a web server where the $_SERVER array (or parts of it - in this case the document_root part) has been disabled. Take into consideration where the script/program has to run and whether it is likely to be moved around to different web servers with different setups. Also, what is the difference between a path that starts with /, versus the same path but that does not have that leading /, or that same path but prefixed with ./? I.e., this: /somepath/includes/file.php This depends on whether the web server is running in a chroot. If the web server for example has access to all files on the machine and isn't running in any kind of chroot or limited setup, then /somepath is located in the very root of the directory on that particular hard drive (or partition) and /somepath is NOT a sub directory of another directory. So you would see something like this (if you are not using Windows): /var/www/mywebsite.com/ /somepath/includes/file.php /usr/sbin/ /home/foo/ versus this: somepath/includes/file.php This depends on where your script is running from. If your script is running in: /var/www/mywebsite.com/myscript.php Then the above would become: /var/www/mywebsite.com/somepath/includes/file.php If your script is running in: /var/www/mywebsite.com/subdirectory/myscript.php Then the above would become: /var/www/mywebsite.com/subdirectory/somepath/includes/file.php versus this: ./somepath/includes/file.php Its the same as somepath/includes/file.php a ./ means current working directory. I hope I make sense. If you haven't already take a look at: http://php.net/manual/en/function.include.php (../ I know) -G --- Mange venlige hilsner/Best regards Kim Naim Lesmer Programmer/Unix systemadministrator Web: www.bitflop.com E-mail : k...@bitflop.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?
On Mon, Jul 6, 2009 at 18:16, Govindagovinda.webdnat...@gmail.com wrote: this is great, but then I still do not have a solution that will work for any level deep of dir/ . I.e. this- dirname(dirname(__FILE__)) gives the correct first part of the path to document root like $_SERVER['DOCUMENT_ROOT'] does only when called from a file that is 2 levels deep. I want something that will work for calling an include from any file that lives n levels deep. That's where you have to define a variable (or constant) that tells the system where the web root is located, and then use that to determine where you are in relation to that. For example: ?php function relate_path($me,$root = '/home/pilotpig/public_html') { if(preg_match('/\/.*\.[a-z0-9]{2,5}$/Ui',$me)) { // If a file with extension 2-5 alphanum chars $me = dirname($me); // Strip the filename // Then loop through the correct number of times. for($i=0;$i(substr_count($me,'/') - substr_count($root,'/'));$i++) { $me = dirname($me); } return $me; // Returns the resulting path. } return false; // If we were unable to get the path. } /* Then use it as follows, presuming this file is named /home/user/public_html/web/home.php */ if(($path = relate_path(__FILE__)) !== false) { include($path.'/include/config.php'); } else { // Handle the error for the incorrect inclusion attempt. } ? Voila! Also, what is the difference between a path that starts with /, versus the same path but that does not have that leading /, or that same path but prefixed with ./? I.e., this: /somepath/includes/file.php is a true (absolute) path. versus this: somepath/includes/file.php is a relative path from wherever the file is called. versus this: ./somepath/includes/file.php is a relative path from the CWD/PWD (Current Working Directory/Present Working Directory). P.S. - The function is untested, just rattled off from my brain while I cook dinner, so if it doesn't work, at least you should get the gist of where I'm going but try it anyway. ;-P -- /Daniel P. Brown daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ Check out our great hosting and dedicated server deals at http://twitter.com/pilotpig -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?
I want something that will work for calling an include from any file that lives n levels deep. That's where you have to define a variable (or constant) that tells the system where the web root is located, and then use that to determine where you are in relation to that. For example: ?php function relate_path($me,$root = '/home/pilotpig/public_html') { if(preg_match('/\/.*\.[a-z0-9]{2,5}$/Ui',$me)) { // If a file with extension 2-5 alphanum chars $me = dirname($me); // Strip the filename // Then loop through the correct number of times. for($i=0;$i(substr_count($me,'/') - substr_count($root,'/')); $i++) { $me = dirname($me); } return $me; // Returns the resulting path. } return false; // If we were unable to get the path. } /* Then use it as follows, presuming this file is named /home/user/public_html/web/home.php */ if(($path = relate_path(__FILE__)) !== false) { include($path.'/include/config.php'); } else { // Handle the error for the incorrect inclusion attempt. } ? Voila! Also, what is the difference between a path that starts with /, versus the same path but that does not have that leading /, or that same path but prefixed with ./? I.e., this: /somepath/includes/file.php is a true (absolute) path. versus this: somepath/includes/file.php is a relative path from wherever the file is called. versus this: ./somepath/includes/file.php is a relative path from the CWD/PWD (Current Working Directory/Present Working Directory). P.S. - The function is untested, just rattled off from my brain while I cook dinner, so if it doesn't work, at least you should get the gist of where I'm going but try it anyway. ;-P Dan I love to see smart hacks in action! ..and I believe I get what you are doing. I am just amazed that there is not a SIMPLE (one-liner) reliable way of just saying document root without a complex function like that. I mean what we need here is a global include path for the shared- hosted user .. an include_path that can be set for the virtual server user and it 'sticks' (does not have to be set on every page load). I think I'll let this all go for now... I have a lot of basics to cover before I trip out too much in any one area. I'm going to need the time and brain juice for some 'real' issues later ;-) -G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?
On Mon, Jul 06, 2009 at 07:15:03PM -0600, Govinda wrote: snip Dan I love to see smart hacks in action! ..and I believe I get what you are doing. I am just amazed that there is not a SIMPLE (one-liner) reliable way of just saying document root without a complex function like that. I mean what we need here is a global include path for the shared- hosted user .. an include_path that can be set for the virtual server user and it 'sticks' (does not have to be set on every page load). I think I'll let this all go for now... I have a lot of basics to cover before I trip out too much in any one area. I'm going to need the time and brain juice for some 'real' issues later ;-) I'm not sure how this could be made simpler. $site_root = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR; Call that in any file in the root of *your* web directories, and you have what is essentially the document root for *your* site. Presumably, you know the *relative* directories of all your files. Simply append those relative directories + filenames to the $site_root variable, and you're done. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to properly build an include path *regardless* from where I am calling the include?
I'm not sure how this could be made simpler. $site_root = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR; Call that in any file in the root of *your* web directories, and you have what is essentially the document root for *your* site. Presumably, you know the *relative* directories of all your files. Simply append those relative directories + filenames to the $site_root variable, and you're done. Paul Paul, you are right. what you say above is very simple. I guess I just did a poor job of communicating what I was after. What I wanted was: ($_SERVER['DOCUMENT_ROOT'] ..but an equivelent that would work on any server, even if ($_SERVER['DOCUMENT_ROOT'] was turned off. SO that I could build a universal global include path that would not break in any page, even if I later moved the page up or down a directory.. never requiring editing, despite the page's URL changes. -G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] best way to properly build an include path *regardless* from where I am calling the include?
I am confusing myself reading the docs just now. i.e.: include_path basename() and dirname() I had thought from many months ago that ?php include '/somedir/somefile.php'; ? would include somefile.php living in somedir regardless from where in the site structure I am calling it. Now it does not seem to be doing that. What is the safest (portable) way to properly build an include path *regardless* from where in my site I am calling the include? If I understand right I can put includes in a dir/ specified by the include_path setting, but I also want to know how to do this from just within the root of my virtual server. -Govinda -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to reinstate radio-button states from database?
On 6/29/09 10:26 PM, Michael A. Peters mpet...@mac.com wrote: Rob Gould wrote: I have a webpage which allows people to log in and make selections with radio buttons and hit SUBMIT and saves the data from those radio buttons to a mySQL database. However, I'm finding that I also need the ability to allow a user to log back in at a later date (or even on a different computer), and pull up that survey again, with each of the 50-something radio-buttons back in the positions in which they were last saved. Surely there's a best-case-method for doing this type of thing (saving large numbers of radio-button-group settings to mySQL and pulling them back again later). Any advice is greatly appreciated. Perhaps there's a jQuery-way to retrieve all the radio-button group settings as an array and save it and pull it back again? Or perhaps a PHP-specific method - - - I'm fine with either. Generate your radio list via php. When the value grabbed from database matches the button value, add a selected=selected to the radio input. Works for me. michael: radios and checkboxes take the checked attribute -- options in selects take the selected attribute. http://www.w3.org/TR/html401/interact/forms.html#checkbox rob: if you use systematic naming of the radio input elements (e.g. a common prefix) then you can use a simple loop to generate an SQL query from the $_POST array to store the form state as a string. then use another loop to generate the markup for all your radios, inserting the checked attribute for those radios whose names appear in the string you stored in the DB. the key is the systematic naming and having a page design (and maybe template scheme, if you like) that allows simple automated generation of the form's markup. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to reinstate radio-button states from database?
Tom Worster wrote: *snip* michael: radios and checkboxes take the checked attribute -- options in selects take the selected attribute. Doh - I knew that. Typo. I always thought it silly there were two different attributes anyway, when they basically are same thing and can never both occur in same tag. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to reinstate radio-button states from database?
On Sun, 2009-06-28 at 21:07 -0400, Bastien Koert wrote: On Sun, Jun 28, 2009 at 7:12 PM, Rob Gouldgould...@mac.com wrote: I have a webpage which allows people to log in and make selections with radio buttons and hit SUBMIT and saves the data from those radio buttons to a mySQL database. However, I'm finding that I also need the ability to allow a user to log back in at a later date (or even on a different computer), and pull up that survey again, with each of the 50-something radio-buttons back in the positions in which they were last saved. Surely there's a best-case-method for doing this type of thing (saving large numbers of radio-button-group settings to mySQL and pulling them back again later). Any advice is greatly appreciated. Perhaps there's a jQuery-way to retrieve all the radio-button group settings as an array and save it and pull it back again? Or perhaps a PHP-specific method - - - I'm fine with either. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I've tended to use a binary string for the values, as my radio/ checkboxs tend to be yes / no, so I store the data in a single field as 010111010101010111000 using 0=no and 1=yes. Then a quick loop through the string sets my values. -- Bastien Cat, the other other white meat Or use a separate survey table to store each answer, and associate it with the user by the index on the users table. Thanks Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to reinstate radio-button states from database?
At 7:12 PM -0400 6/28/09, Rob Gould wrote: I have a webpage which allows people to log in and make selections with radio buttons and hit SUBMIT and saves the data from those radio buttons to a mySQL database. However, I'm finding that I also need the ability to allow a user to log back in at a later date (or even on a different computer), and pull up that survey again, with each of the 50-something radio-buttons back in the positions in which they were last saved. Surely there's a best-case-method for doing this type of thing (saving large numbers of radio-button-group settings to mySQL and pulling them back again later). Any advice is greatly appreciated. Perhaps there's a jQuery-way to retrieve all the radio-button group settings as an array and save it and pull it back again? Or perhaps a PHP-specific method - - - I'm fine with either. Rob: I don't know the best way, but this is the way I do it. My database is relational. Each user has an unique ID as well as each question has a unique ID and the answer to each question is the one of several different choices (1 to whatever). Each answer is recorded in the database as a *separate* record that contains the user ID, question ID and their choice. A record might look like this: Table: answers Fields: user_id, question_id, answer Values: 34,115,5 That's where 34 is the user's ID, 115 is the question's ID, and 5 is the user's choice. Then whenever you wanted to pull out and show the user (user 34 for example) what they picked, just select all the records that have a user ID of 34 and sort them by question ID and show the selections the user made. If you have different test, then add a unique test_id field and make the question_id non-unique. An example might be: Table: answers Fields: user_id, test_id, question_id, answer Values: 34,20,11,5 That's where 34 is the user's ID, 20 is the test's ID, 11 is the question's ID, and 5 is the user's choice. Then you could pull out all records that have the same user ID and test ID and show the questions and answers associated with that test and that user. That works for me. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to reinstate radio-button states from database?
Rob Gould wrote: I have a webpage which allows people to log in and make selections with radio buttons and hit SUBMIT and saves the data from those radio buttons to a mySQL database. However, I'm finding that I also need the ability to allow a user to log back in at a later date (or even on a different computer), and pull up that survey again, with each of the 50-something radio-buttons back in the positions in which they were last saved. Surely there's a best-case-method for doing this type of thing (saving large numbers of radio-button-group settings to mySQL and pulling them back again later). Any advice is greatly appreciated. Perhaps there's a jQuery-way to retrieve all the radio-button group settings as an array and save it and pull it back again? Or perhaps a PHP-specific method - - - I'm fine with either. Generate your radio list via php. When the value grabbed from database matches the button value, add a selected=selected to the radio input. Works for me. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Best way to reinstate radio-button states from database?
I have a webpage which allows people to log in and make selections with radio buttons and hit SUBMIT and saves the data from those radio buttons to a mySQL database. However, I'm finding that I also need the ability to allow a user to log back in at a later date (or even on a different computer), and pull up that survey again, with each of the 50-something radio-buttons back in the positions in which they were last saved. Surely there's a best-case-method for doing this type of thing (saving large numbers of radio-button-group settings to mySQL and pulling them back again later). Any advice is greatly appreciated. Perhaps there's a jQuery-way to retrieve all the radio-button group settings as an array and save it and pull it back again? Or perhaps a PHP-specific method - - - I'm fine with either. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to reinstate radio-button states from database?
On Sun, Jun 28, 2009 at 7:12 PM, Rob Gouldgould...@mac.com wrote: I have a webpage which allows people to log in and make selections with radio buttons and hit SUBMIT and saves the data from those radio buttons to a mySQL database. However, I'm finding that I also need the ability to allow a user to log back in at a later date (or even on a different computer), and pull up that survey again, with each of the 50-something radio-buttons back in the positions in which they were last saved. Surely there's a best-case-method for doing this type of thing (saving large numbers of radio-button-group settings to mySQL and pulling them back again later). Any advice is greatly appreciated. Perhaps there's a jQuery-way to retrieve all the radio-button group settings as an array and save it and pull it back again? Or perhaps a PHP-specific method - - - I'm fine with either. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I've tended to use a binary string for the values, as my radio/ checkboxs tend to be yes / no, so I store the data in a single field as 010111010101010111000 using 0=no and 1=yes. Then a quick loop through the string sets my values. -- Bastien Cat, the other other white meat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] best way to communicate between PHP, Flash/Actionscript across LAN
At 12:33 PM -0700 6/23/09, Daevid Vincent wrote: Other solutions seem to involve (hackishly) polling every x seconds. Seems there should be a better way. d There might not be a better solution. This is an example of javascript poling a php script: http://webbytedd.com/b/timed-php/ This is simply client-side - sever-side communication. How that might solve your problem is beyond my understanding of what you are trying to do. I'm not a hardware guy. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] best way to communicate between PHP, Flash/Actionscript across LAN
At 10:30 AM -0400 6/24/09, tedd wrote: At 12:33 PM -0700 6/23/09, Daevid Vincent wrote: Other solutions seem to involve (hackishly) polling every x seconds. Seems there should be a better way. d There might not be a better solution. This is an example of javascript poling a php script: Before Rob beats me to it, I should have said: This is an example of javascript polling a php script: Next thing I know, he'll be asking just how can javascript stick it to php? :-) Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] best way to communicate between PHP, Flash/Actionscript across LAN
I have a demo to create for a tradeshow. We have 3 touch screens and 3 50 plasmas and 3 G1 (android WiFi) phones. Our own LAN/Router/Wi-Fi. I need a way so that I can use web pages and Flash (actionscript) to make stuff happen on any of the displays/phones. So you click a button on the touch screen and see something happen on the plasma. Or G1 interface application triggers .flv on touch screen, etc. So I need some kind of messaging queue over the LAN and that each CPU can both send and recieve? I could use mySQL as an intermediary to store the data (like strings of text entered or whatever and pass the record IDs around), or use some other XML/JSON/AJAX or something. I just don't even know what I'm talking about really. Is this what DBUS is for? It must work with PHP as we'll have web pages triggering the .flv as well and of course ActionScript has to be able to work with it (that's why I was thinking mySQL, AJAX, XML, etc.). Ideas? Suggestions? someone was telling me about AMQP or RabbitMQ. But neither is PHP-ified that I can tell. http://www.nabble.com/PHP-AMQP-client--td12935751.html ...and I realize that PHP will run in a web page mostly and I'll have to do some magic like polling something (like a daemon or DB) via JS/AJAX to see if I need to pop-up an alert or whatever -- much like a bulletin board does when you get new mail. Step 1: get communication between all computers to work Step 2: Step 3: profit!
Re: [PHP] best way to communicate between PHP, Flash/Actionscript across LAN
On Tue, Jun 23, 2009 at 2:32 PM, Daevid Vincentdae...@daevid.com wrote: I have a demo to create for a tradeshow. We have 3 touch screens and 3 50 plasmas and 3 G1 (android WiFi) phones. Our own LAN/Router/Wi-Fi. I need a way so that I can use web pages and Flash (actionscript) to make stuff happen on any of the displays/phones. So you click a button on the touch screen and see something happen on the plasma. Or G1 interface application triggers .flv on touch screen, etc. So I need some kind of messaging queue over the LAN and that each CPU can both send and recieve? I could use mySQL as an intermediary to store the data (like strings of text entered or whatever and pass the record IDs around), or use some other XML/JSON/AJAX or something. I just don't even know what I'm talking about really. Is this what DBUS is for? It must work with PHP as we'll have web pages triggering the .flv as well and of course ActionScript has to be able to work with it (that's why I was thinking mySQL, AJAX, XML, etc.). Ideas? Suggestions? someone was telling me about AMQP or RabbitMQ. But neither is PHP-ified that I can tell. http://www.nabble.com/PHP-AMQP-client--td12935751.html ...and I realize that PHP will run in a web page mostly and I'll have to do some magic like polling something (like a daemon or DB) via JS/AJAX to see if I need to pop-up an alert or whatever -- much like a bulletin board does when you get new mail. Step 1: get communication between all computers to work Step 2: Step 3: profit! XML is the preferred method for doing communication with Flex/Flash...perhaps AJAX to handle it all in the background -- Bastien Cat, the other other white meat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] best way to communicate between PHP, Flash/Actionscript across LAN
-Original Message- From: Bastien Koert [mailto:phps...@gmail.com] Sent: Tuesday, June 23, 2009 12:30 PM To: Daevid Vincent Cc: php-general@lists.php.net Subject: Re: [PHP] best way to communicate between PHP, Flash/Actionscript across LAN On Tue, Jun 23, 2009 at 2:32 PM, Daevid Vincentdae...@daevid.com wrote: I have a demo to create for a tradeshow. We have 3 touch screens and 3 50 plasmas and 3 G1 (android WiFi) phones. Our own LAN/Router/Wi-Fi. I need a way so that I can use web pages and Flash (actionscript) to make stuff happen on any of the displays/phones. So you click a button on the touch screen and see something happen on the plasma. Or G1 interface application triggers .flv on touch screen, etc. So I need some kind of messaging queue over the LAN and that each CPU can both send and recieve? I could use mySQL as an intermediary to store the data (like strings of text entered or whatever and pass the record IDs around), or use some other XML/JSON/AJAX or something. I just don't even know what I'm talking about really. Is this what DBUS is for? It must work with PHP as we'll have web pages triggering the .flv as well and of course ActionScript has to be able to work with it (that's why I was thinking mySQL, AJAX, XML, etc.). Ideas? Suggestions? someone was telling me about AMQP or RabbitMQ. But neither is PHP-ified that I can tell. http://www.nabble.com/PHP-AMQP-client--td12935751.html ...and I realize that PHP will run in a web page mostly and I'll have to do some magic like polling something (like a daemon or DB) via JS/AJAX to see if I need to pop-up an alert or whatever -- much like a bulletin board does when you get new mail. Step 1: get communication between all computers to work Step 2: Step 3: profit! XML is the preferred method for doing communication with Flex/Flash...perhaps AJAX to handle it all in the background I'm not so much interested in the transport payload as I am the how. I need daemons and message queues and that sort of thing that work over TCP/IP. Writing a PHP daemon is not the way to do this I'm sure of that, however I need PHP to be able to talk to it. I thought about DBUS, but that's more for services within a single host computer. Other solutions seem to involve (hackishly) polling every x seconds. Seems there should be a better way. d -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way to communicate between PHP, Flash/Actionscript across LAN
On Tue, Jun 23, 2009 at 3:33 PM, Daevid Vincentdae...@daevid.com wrote: -Original Message- From: Bastien Koert [mailto:phps...@gmail.com] Sent: Tuesday, June 23, 2009 12:30 PM To: Daevid Vincent Cc: php-general@lists.php.net Subject: Re: [PHP] best way to communicate between PHP, Flash/Actionscript across LAN On Tue, Jun 23, 2009 at 2:32 PM, Daevid Vincentdae...@daevid.com wrote: I have a demo to create for a tradeshow. We have 3 touch screens and 3 50 plasmas and 3 G1 (android WiFi) phones. Our own LAN/Router/Wi-Fi. I need a way so that I can use web pages and Flash (actionscript) to make stuff happen on any of the displays/phones. So you click a button on the touch screen and see something happen on the plasma. Or G1 interface application triggers .flv on touch screen, etc. So I need some kind of messaging queue over the LAN and that each CPU can both send and recieve? I could use mySQL as an intermediary to store the data (like strings of text entered or whatever and pass the record IDs around), or use some other XML/JSON/AJAX or something. I just don't even know what I'm talking about really. Is this what DBUS is for? It must work with PHP as we'll have web pages triggering the .flv as well and of course ActionScript has to be able to work with it (that's why I was thinking mySQL, AJAX, XML, etc.). Ideas? Suggestions? someone was telling me about AMQP or RabbitMQ. But neither is PHP-ified that I can tell. http://www.nabble.com/PHP-AMQP-client--td12935751.html ...and I realize that PHP will run in a web page mostly and I'll have to do some magic like polling something (like a daemon or DB) via JS/AJAX to see if I need to pop-up an alert or whatever -- much like a bulletin board does when you get new mail. Step 1: get communication between all computers to work Step 2: Step 3: profit! XML is the preferred method for doing communication with Flex/Flash...perhaps AJAX to handle it all in the background I'm not so much interested in the transport payload as I am the how. I need daemons and message queues and that sort of thing that work over TCP/IP. Writing a PHP daemon is not the way to do this I'm sure of that, however I need PHP to be able to talk to it. I thought about DBUS, but that's more for services within a single host computer. Other solutions seem to involve (hackishly) polling every x seconds. Seems there should be a better way. d -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php What about a comet Server ? http://www.zeitoun.net/articles/comet_and_php/start -- Bastien Cat, the other other white meat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Best way to deal with $_SERVER['REQUEST_URI'] on IIS?
Hi all, Apparently, $_SERVER['REQUEST_URI'] doesn't get set the same way when running PHP on IIS as when running it on Apache. Specifically, it seems to contain the script name only, and not the query string part. I know I can rewrite my code to piece together a $_SERVER['REQUEST_URI'] from $_SERVER['SCRIPT_NAME'] and $_SERVER['QUERY_STRING'], but some instances of $_SERVER['REQUEST_URI'] are in third party scripts which would be a bit of a pain to fix every time they are updated. It is a known problem since there are several mentions and workarounds to be found on the Internet, but I'm wondering which is currently the best way to deal with it. I don't personally run PHP with IIS, so I haven't encountered this problem before...but now I have a user who does. I could potentially have more users who encounter the same thing, so the easier the instructions and the less tinkering, the better. Is there a php.ini setting, for instance? What have you found that works for you? Thanks, Mattias -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to deal with $_SERVER['REQUEST_URI'] on IIS?
On Tue, Apr 21, 2009 at 4:04 PM, Mattias Thorslund matt...@thorslund.us wrote: Hi all, Apparently, $_SERVER['REQUEST_URI'] doesn't get set the same way when running PHP on IIS as when running it on Apache. Specifically, it seems to contain the script name only, and not the query string part. I know I can rewrite my code to piece together a $_SERVER['REQUEST_URI'] from $_SERVER['SCRIPT_NAME'] and $_SERVER['QUERY_STRING'], but some instances of $_SERVER['REQUEST_URI'] are in third party scripts which would be a bit of a pain to fix every time they are updated. It is a known problem since there are several mentions and workarounds to be found on the Internet, but I'm wondering which is currently the best way to deal with it. I don't personally run PHP with IIS, so I haven't encountered this problem before...but now I have a user who does. I could potentially have more users who encounter the same thing, so the easier the instructions and the less tinkering, the better. Is there a php.ini setting, for instance? What have you found that works for you? Thanks, Mattias It works just fine on the servers where I work. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to deal with $_SERVER['REQUEST_URI'] on IIS?
Andrew Ballard wrote: On Tue, Apr 21, 2009 at 4:04 PM, Mattias Thorslund matt...@thorslund.us wrote: Hi all, Apparently, $_SERVER['REQUEST_URI'] doesn't get set the same way when running PHP on IIS as when running it on Apache. Specifically, it seems to contain the script name only, and not the query string part. I know I can rewrite my code to piece together a $_SERVER['REQUEST_URI'] from $_SERVER['SCRIPT_NAME'] and $_SERVER['QUERY_STRING'], but some instances of $_SERVER['REQUEST_URI'] are in third party scripts which would be a bit of a pain to fix every time they are updated. It is a known problem since there are several mentions and workarounds to be found on the Internet, but I'm wondering which is currently the best way to deal with it. I don't personally run PHP with IIS, so I haven't encountered this problem before...but now I have a user who does. I could potentially have more users who encounter the same thing, so the easier the instructions and the less tinkering, the better. Is there a php.ini setting, for instance? What have you found that works for you? Thanks, Mattias It works just fine on the servers where I work. Andrew Thanks Andrew. I just read that there is supposedly a fix for this in FastCGI: http://ruslany.net/2008/08/update-for-iis-70-fastcgi-module/ You might have that update already. If this fix works, then it's obviously the best solution to the problem. Cheers, Mattias -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to deal with $_SERVER['REQUEST_URI'] on IIS?
On Tue, Apr 21, 2009 at 4:21 PM, Mattias Thorslund matt...@thorslund.us wrote: Andrew Ballard wrote: On Tue, Apr 21, 2009 at 4:04 PM, Mattias Thorslund matt...@thorslund.us wrote: Hi all, Apparently, $_SERVER['REQUEST_URI'] doesn't get set the same way when running PHP on IIS as when running it on Apache. Specifically, it seems to contain the script name only, and not the query string part. I know I can rewrite my code to piece together a $_SERVER['REQUEST_URI'] from $_SERVER['SCRIPT_NAME'] and $_SERVER['QUERY_STRING'], but some instances of $_SERVER['REQUEST_URI'] are in third party scripts which would be a bit of a pain to fix every time they are updated. It is a known problem since there are several mentions and workarounds to be found on the Internet, but I'm wondering which is currently the best way to deal with it. I don't personally run PHP with IIS, so I haven't encountered this problem before...but now I have a user who does. I could potentially have more users who encounter the same thing, so the easier the instructions and the less tinkering, the better. Is there a php.ini setting, for instance? What have you found that works for you? Thanks, Mattias It works just fine on the servers where I work. Andrew Thanks Andrew. I just read that there is supposedly a fix for this in FastCGI: http://ruslany.net/2008/08/update-for-iis-70-fastcgi-module/ You might have that update already. If this fix works, then it's obviously the best solution to the problem. Cheers, Mattias I'm pretty sure we're using ISAPI right now. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Best way to post XML via curl?
I'm going crazy, can't quite get this encoding to work. I've tried all the various combinations, trying to send this block $xml (which is a simple string variable) via post along with 3 other params: $postArgs = http_build_query(array('method'='newPrintRequest', 'login'=$login, 'password'=$password, 'orderxml'=$xml)); $ch = curl_init('http://test.server.com/rest_interface.php'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postArgs); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array(Content-Type: text/xml)); $response = curl_exec($ch); Is this use of http_build_query the best way to send XML? Any other curl options I should be setting? I tried urlencoding() the $xml, I tried htmlspecialchars(), I tried nothing at all, I tried amp and is there a best practice for how a big block of xml should be posted? :-( -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to post XML via curl?
Just realized I didn't happen to mention the problem. :-) The server is not seeing any of my posted fields. It's returning a properly-formatted XML response that says I did not submit the required fields. Unfortunately the server is a black box, but lots of other partners use it every day and supposedly there are no problems server side. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to post XML via curl?
2009/2/12 Brian Dunning br...@briandunning.com: I'm going crazy, can't quite get this encoding to work. I've tried all the various combinations, trying to send this block $xml (which is a simple string variable) via post along with 3 other params: $postArgs = http_build_query(array('method'='newPrintRequest', 'login'=$login, 'password'=$password, 'orderxml'=$xml)); $ch = curl_init('http://test.server.com/rest_interface.php'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postArgs); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array(Content-Type: text/xml)); Drop the above line and I reckon it should work. The content you're sending is not XML, it's form fields which CURL will default to. It just happens that one of those fields is XML. $response = curl_exec($ch); Is this use of http_build_query the best way to send XML? Any other curl options I should be setting? I tried urlencoding() the $xml, I tried htmlspecialchars(), I tried nothing at all, I tried amp and is there a best practice for how a big block of xml should be posted? -Stuart -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to post XML via curl?
This line is the key. WITH the line, I get a properly formatted XML response from the server, telling me that I did not send any valid post fields. WITHOUT the line, all I get back from the server is a '1' and their tech reports that no valid call was received from me. On Feb 11, 2009, at 4:56 PM, Stuart wrote: curl_setopt($ch, CURLOPT_HTTPHEADER, array(Content-Type: text/ xml)); Drop the above line and I reckon it should work. The content you're sending is not XML, it's form fields which CURL will default to. It just happens that one of those fields is XML. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to post XML via curl?
2009/2/12 Brian Dunning br...@briandunning.com: This line is the key. WITH the line, I get a properly formatted XML response from the server, telling me that I did not send any valid post fields. WITHOUT the line, all I get back from the server is a '1' and their tech reports that no valid call was received from me. In that case you're not sending them what they're asking for. Are the method, login and password fields supposed to be separate or should they be included in the xml? At the moment they're separate so when you tell the server it's in XML format you're lying because only part of it is. As a test try setting $postArgs = $xml. If I'm right it might either work or give you and authentication error. -Stuart On Feb 11, 2009, at 4:56 PM, Stuart wrote: curl_setopt($ch, CURLOPT_HTTPHEADER, array(Content-Type: text/xml)); Drop the above line and I reckon it should work. The content you're sending is not XML, it's form fields which CURL will default to. It just happens that one of those fields is XML. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to post XML via curl?
From the documentation: Parameters The following POST parameters are required: login - Assigned password - Assigned method - newPrintRequest, updatePrintRequest, reprintRequest orderxml - XML according to accompanying documentation The error that I get says no method was provided, and if you look at my code, it clearly is. On Feb 11, 2009, at 5:08 PM, Stuart wrote: 2009/2/12 Brian Dunning br...@briandunning.com: This line is the key. WITH the line, I get a properly formatted XML response from the server, telling me that I did not send any valid post fields. WITHOUT the line, all I get back from the server is a '1' and their tech reports that no valid call was received from me. In that case you're not sending them what they're asking for. Are the method, login and password fields supposed to be separate or should they be included in the xml? At the moment they're separate so when you tell the server it's in XML format you're lying because only part of it is. As a test try setting $postArgs = $xml. If I'm right it might either work or give you and authentication error. -Stuart On Feb 11, 2009, at 4:56 PM, Stuart wrote: curl_setopt($ch, CURLOPT_HTTPHEADER, array(Content-Type: text/ xml)); Drop the above line and I reckon it should work. The content you're sending is not XML, it's form fields which CURL will default to. It just happens that one of those fields is XML. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to post XML via curl?
2009/2/12 Brian Dunning br...@briandunning.com: From the documentation: Parameters The following POST parameters are required: login - Assigned password - Assigned method - newPrintRequest, updatePrintRequest, reprintRequest orderxml - XML according to accompanying documentation The error that I get says no method was provided, and if you look at my code, it clearly is. The original code you had, minus the Content-Type header will do exactly that. Either the documentation is wrong or there's something wrong with their system. I suggest you create an HTML file containing a form with those fields that posts to the destination URL, fill it in with valid values and see what happens when you post that. Remove CURL from the equation, and if that doesn't work go back to them and show them that form and the response you get, because according to that documentation it should work. -Stuart On Feb 11, 2009, at 5:08 PM, Stuart wrote: 2009/2/12 Brian Dunning br...@briandunning.com: This line is the key. WITH the line, I get a properly formatted XML response from the server, telling me that I did not send any valid post fields. WITHOUT the line, all I get back from the server is a '1' and their tech reports that no valid call was received from me. In that case you're not sending them what they're asking for. Are the method, login and password fields supposed to be separate or should they be included in the xml? At the moment they're separate so when you tell the server it's in XML format you're lying because only part of it is. As a test try setting $postArgs = $xml. If I'm right it might either work or give you and authentication error. -Stuart On Feb 11, 2009, at 4:56 PM, Stuart wrote: curl_setopt($ch, CURLOPT_HTTPHEADER, array(Content-Type: text/xml)); Drop the above line and I reckon it should work. The content you're sending is not XML, it's form fields which CURL will default to. It just happens that one of those fields is XML. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to recieve image from url?
... You could read it progressively using fopen(), fread() et al. Probably. This would mean only a small amount of data is read by yours erver at once. Eg: $rp = fopen('http:www.example.com/title.png', 'r'); $wp = fopen('mylocalfile', 'w'); while ($block = fread($rp, 8192)) { // 8k block size fwrite($wp, $block); } fclose($rp); fclose($wp); From memory. Something like that. Fopen() modes may need tweaking. -- Richard Heyes HTML5 Graphing for FF, Chrome, Opera and Safari: http://www.rgraph.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Best way to recieve image from url?
Hi, I have this function: function saveImageFromUrl($image_url, $image_save) { $contents = file_get_contents($image_url); $fp = fopen($image_save, 'w'); fwrite($fp, $contents); fclose($fp); } As you can see it fetches the images contents and write them to new image on my local directory. Is this is the best way to do this? (I don't have curl) Does file_get_contents() uses buffer to get the contents of the image? (in case the server response is slow) There is a better way? Thanks in Advance, Nitsan
Re: [PHP] Best way to recieve image from url?
On Oct 20, 2008, at 12:46 AM, Nitsan Bin-Nun wrote: Hi, I have this function: function saveImageFromUrl($image_url, $image_save) { $contents = file_get_contents($image_url); $fp = fopen($image_save, 'w'); fwrite($fp, $contents); fclose($fp); } As you can see it fetches the images contents and write them to new image on my local directory. Is this is the best way to do this? (I don't have curl) Does file_get_contents() uses buffer to get the contents of the image? (in case the server response is slow) the server will respond slow either way if it is slow to respond. There is a better way? Thanks in Advance, Nitsan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to recieve image from url?
On Sun, Oct 19, 2008 at 6:46 PM, Nitsan Bin-Nun [EMAIL PROTECTED] wrote: As you can see it fetches the images contents and write them to new image on my local directory. Is this is the best way to do this? (I don't have curl) Do you have GET or wget on your server, with exec() privileges to use them? Your method is good for cross-platform usage, but won't follow redirects. Does file_get_contents() uses buffer to get the contents of the image? (in case the server response is slow) There is a better way? As Borge suggested, it won't speed things up for you if the remote server is slow, but if I understand you correctly, you want to know if there's a way to keep it running on your end. Check into either using it as a cron job, a forked process, or by setting max_execution_time and ignore_user_abort(), et al. -- /Daniel P. Brown More full-root dedicated server packages: Intel 2.4GHz/60GB/512MB/2TB $49.99/mo. Intel 3.06GHz/80GB/1GB/2TB $59.99/mo. Intel 2.4GHz/320/GB/1GB/3TB $74.99/mo. Dedicated servers, VPS, and hosting from $2.50/mo. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to recieve image from url?
If you're using file_get_contents, why aren't you using file_put_contents? Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com Nitsan Bin-Nun wrote: Hi, I have this function: function saveImageFromUrl($image_url, $image_save) { $contents = file_get_contents($image_url); $fp = fopen($image_save, 'w'); fwrite($fp, $contents); fclose($fp); } As you can see it fetches the images contents and write them to new image on my local directory. Is this is the best way to do this? (I don't have curl) Does file_get_contents() uses buffer to get the contents of the image? (in case the server response is slow) There is a better way? Thanks in Advance, Nitsan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way for PHP page
On Jan 1, 2008 11:17 PM, Alain Roger [EMAIL PROTECTED] wrote: Hi, i would like to improve my coding quality when i use PHP code and for that i would request your help. in my web developer experience, i have to confess that i've never succeeded in spliting PHP code from HTML code. i mean that all my web pages consist of PHP code mixed with HTML code (for rendering pages). Some developers tell it's possible to write only PHP code for web page. i agree with them but only when those PHP pages do not render web elements (write text, display pictures, display formular, ...). the purpose of my post is to know if i can really (at 100%) split client code (display images, write text,...) from server code (move or copy data to DB, create connection objects,...) so what do you think about that ? -- Alain Windows XP SP2 PostgreSQL 8.2.4 / MS SQL server 2005 Apache 2.2.4 PHP 5.2.4 C# 2005-2008 Yes, you can. function foo() { global $data; //Fetch from database, format, etc. etc. //Stuff all the data into $data variable } function bar() { global $data; //Output with HTML } $data = array(); foo(); bar(); I'm pretty sure this is what they mean. -Casey -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way for PHP page
On Wednesday 02 January 2008 09:17:50 Alain Roger wrote: Hi, i would like to improve my coding quality when i use PHP code and for that i would request your help. in my web developer experience, i have to confess that i've never succeeded in spliting PHP code from HTML code. i mean that all my web pages consist of PHP code mixed with HTML code (for rendering pages). Some developers tell it's possible to write only PHP code for web page. i agree with them but only when those PHP pages do not render web elements (write text, display pictures, display formular, ...). the purpose of my post is to know if i can really (at 100%) split client code (display images, write text,...) from server code (move or copy data to DB, create connection objects,...) so what do you think about that ? Hello, I believe TYPO3 has good implementation about splitting code and template. And to archieve clean php code. 1-) Left html ?php echo $this; ?/html model development 2-) Find good template engine. (no not that smarty, it was too big) 3-) use strict dicipline to move html to outside of the code. Also if you can use the php based template files you can lift off the template overhead. like. template.php $strPage = html head. title.$strPageTitle./title /head body table tr td.$strLeftBlock./td td.$strRigthBlock./td /tr /table /body /html; process.php $strPageTitle = getPageTitle($_REQUEST['page']); $strLeftBlock = getPageBlock($_REQUEST['page'],'left'); $strRightBlock = getPageBlock($_REQUEST['page'],'right'); include('template.php'); echo $strPage; regards Sancar -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way for PHP page
i would like to improve my coding quality when i use PHP code and for that i would request your help. in my web developer experience, i have to confess that i've never succeeded in spliting PHP code from HTML code. There's a myth that by separating html and php your code is cleaner, it's a little more than that. What you should consider doing is separating the business logic from the display logic. The business logic includes things like database calls, data calculations, etc. Display logic is what the page actually looks like. This will likely include both HTML and PHP, but the PHP will be limited to echoing out variables, as you should have already done all calculations. One very good way to do this separation is by using the MVC pattern - http://en.wikipedia.org/wiki/Model-view-controller . I've found that using the MVC pattern helps me to write cleaner, more maintainable code as you always know where the code for a given function is located. Need to edit what the page looks like? It's in the view. Need to edit your database calls? It's in the model. Anything else? It's in the controller. There are lots of great frameworks out there that use the MVC pattern. Personally I use and recommend CodeIgniter (http:// www.codeigniter.com) - it's been a great one for me, but there are plenty of other well written frameworks out there if CodeIgniter isn't a good fit for you. HTH, Brady -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] best way for PHP page
On Jan 2, 2008 2:17 AM, Alain Roger [EMAIL PROTECTED] wrote: Hi, i would like to improve my coding quality when i use PHP code and for that i would request your help. in my web developer experience, i have to confess that i've never succeeded in spliting PHP code from HTML code. i mean that all my web pages consist of PHP code mixed with HTML code (for rendering pages). Some developers tell it's possible to write only PHP code for web page. i agree with them but only when those PHP pages do not render web elements (write text, display pictures, display formular, ...). the purpose of my post is to know if i can really (at 100%) split client code (display images, write text,...) from server code (move or copy data to DB, create connection objects,...) so what do you think about that ? study up on mvc http://en.wikipedia.org/wiki/Model-view-controller then look at some of the popular open source php implementations. code igniter is very thin and straightforward. you can quickly see how a php application can be separated into layers. -nathan
Re: [PHP] best way for PHP page
If MVC is too heavy for you it may also be worth exploring templating engines such as Smarty: http://www.smarty.net/ On Jan 2, 2008 4:10 PM, Nathan Nobbe [EMAIL PROTECTED] wrote: On Jan 2, 2008 2:17 AM, Alain Roger [EMAIL PROTECTED] wrote: Hi, i would like to improve my coding quality when i use PHP code and for that i would request your help. in my web developer experience, i have to confess that i've never succeeded in spliting PHP code from HTML code. i mean that all my web pages consist of PHP code mixed with HTML code (for rendering pages). Some developers tell it's possible to write only PHP code for web page. i agree with them but only when those PHP pages do not render web elements (write text, display pictures, display formular, ...). the purpose of my post is to know if i can really (at 100%) split client code (display images, write text,...) from server code (move or copy data to DB, create connection objects,...) so what do you think about that ? study up on mvc http://en.wikipedia.org/wiki/Model-view-controller then look at some of the popular open source php implementations. code igniter is very thin and straightforward. you can quickly see how a php application can be separated into layers. -nathan
Re: [PHP] best way for PHP page
At 8:17 AM +0100 1/2/08, Alain Roger wrote: the purpose of my post is to know if i can really (at 100%) split client code (display images, write text,...) from server code (move or copy data to DB, create connection objects,...) so what do you think about that ? Alain: What do I think about that? I think there is only one web language and it's called php/mysql/html/js/css. For no one language can do it all. The bigger point is to learn how to separate data, presentation, and functionality. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] best way for PHP page
Hi, i would like to improve my coding quality when i use PHP code and for that i would request your help. in my web developer experience, i have to confess that i've never succeeded in spliting PHP code from HTML code. i mean that all my web pages consist of PHP code mixed with HTML code (for rendering pages). Some developers tell it's possible to write only PHP code for web page. i agree with them but only when those PHP pages do not render web elements (write text, display pictures, display formular, ...). the purpose of my post is to know if i can really (at 100%) split client code (display images, write text,...) from server code (move or copy data to DB, create connection objects,...) so what do you think about that ? -- Alain Windows XP SP2 PostgreSQL 8.2.4 / MS SQL server 2005 Apache 2.2.4 PHP 5.2.4 C# 2005-2008
[PHP] Best way to allow users to post youtube video links ?
I want to allow people to be able to post links to videos on youtube. I've implemented it in a certain way by allowing them to copy the embed tag into a textarea and then submit the form. I pick up the form data, validate and display on the site. Is there any better way to do this or php plugins out there ? Cheers Don. - Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.
Re: [PHP] Best way to allow users to post youtube video links ?
Just a thought.. it might be better to control the output a little more. I assume if you're letting them submit the embed code that you're turning around and just displaying what they posted. It might be easier for the user and more secure if you have them submit either the full youtube URL: http://www.youtube.com/watch?v=Tq8Yw19bn7Q and/or you can have people just submit the video ID: Tq8Yw19bn7Q Either way, that's all you need to create your own embed tag without trusting that they're not going to submit something bad with their embed. There are things to facilitate YouTube link posting in various systems including Joomla and many subcomponents, phpBB, probably most other forum software. If you're using something like that, you might search around. -TG - Original Message - From: Don Don [EMAIL PROTECTED] To: PHP List php-general@lists.php.net Date: Thu, 20 Dec 2007 08:20:16 -0800 (PST) Subject: [PHP] Best way to allow users to post youtube video links ? I want to allow people to be able to post links to videos on youtube. I've implemented it in a certain way by allowing them to copy the embed tag into a textarea and then submit the form. I pick up the form data, validate and display on the site. Is there any better way to do this or php plugins out there ? Cheers Don. - Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to automatically get mySQL database.
Hi Jay Thanks again, Now how would I do the SELECT remote_stuff INTO local_table; ? as these are on two different MySQL connections? Im not sure if this is possible to do in one statement or query? Seems possible in theory but I'm not sure. original message: Im wondering the best to do this. Is it to get all the information into result sets for each table and then delete the contents of each local table and then looping through the result sets just insert the information into the local tables? This seems like a good solution but I wonder if there are any out there before going ahead with development. [/snip] TRUNCATE local_table; SELECT remote_stuff INTO local_table; -- Angelo Zanetti Systems developer *Telephone:* +27 (021) 552 9799 *Mobile:* +27 (0) 72 441 3355 *Fax:*+27 (0) 86 681 5885 * Web:* http://www.zlogic.co.za *E-Mail:* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Best way to automatically get mySQL database.
hi guys. We've got a local system (PHP intranet) and we need to connect to a live mySQL server get some of the tables (contents) and overwrite the same tables in the local mySQL database. This needs to be done with PHP. Im wondering the best to do this. Is it to get all the information into result sets for each table and then delete the contents of each local table and then looping through the result sets just insert the information into the local tables? This seems like a good solution but I wonder if there are any out there before going ahead with development. Let me know your views etc... Thanks in advance -- Angelo Zanetti Systems developer *Telephone:* +27 (021) 552 9799 *Mobile:* +27 (0) 72 441 3355 *Fax:*+27 (0) 86 681 5885 * Web:* http://www.zlogic.co.za *E-Mail:* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Best way to automatically get mySQL database.
[snip] We've got a local system (PHP intranet) and we need to connect to a live mySQL server get some of the tables (contents) and overwrite the same tables in the local mySQL database. This needs to be done with PHP. Im wondering the best to do this. Is it to get all the information into result sets for each table and then delete the contents of each local table and then looping through the result sets just insert the information into the local tables? This seems like a good solution but I wonder if there are any out there before going ahead with development. [/snip] TRUNCATE local_table; SELECT remote_stuff INTO local_table; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to automatically get mySQL database.
thanks thought there was something simpler Jay Blanchard wrote: [snip] We've got a local system (PHP intranet) and we need to connect to a live mySQL server get some of the tables (contents) and overwrite the same tables in the local mySQL database. This needs to be done with PHP. Im wondering the best to do this. Is it to get all the information into result sets for each table and then delete the contents of each local table and then looping through the result sets just insert the information into the local tables? This seems like a good solution but I wonder if there are any out there before going ahead with development. [/snip] TRUNCATE local_table; SELECT remote_stuff INTO local_table; -- Angelo Zanetti Systems developer *Telephone:* +27 (021) 552 9799 *Mobile:* +27 (0) 72 441 3355 *Fax:*+27 (0) 86 681 5885 * Web:* http://www.zlogic.co.za *E-Mail:* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Best way to convert Little-Endian DWORD to string
Hi, Maybe quite strange question and quite off topic, but there's PHP involved :) I want to read out files, and then I come across 4byte DWORD values, they are stored in little endian values, but how do I get in a PHP string (as the values are too large for integer) My code is currently this: $data = fread($fp,4); $value = (ord(substr($data,3,1))*256*256*256)+(ord(substr($data,2,1))*256*256)+(ord(substr($data,1,1))*256)+(ord(substr($data,0,1))); and now $value contains the value of the DWORD, it works fine, but it seems that it could be done a lot easier :) Anyone experience with it? Tijnema -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Best way to convert Little-Endian DWORD to string
-Original Message- From: Tijnema [mailto:[EMAIL PROTECTED] Sent: 30 May 2007 15:20 To: php Subject: [PHP] Best way to convert Little-Endian DWORD to string Hi, Maybe quite strange question and quite off topic, but there's PHP involved :) I want to read out files, and then I come across 4byte DWORD values, they are stored in little endian values, but how do I get in a PHP string (as the values are too large for integer) My code is currently this: $data = fread($fp,4); $value = (ord(substr($data,3,1))*256*256*256)+(ord(substr($data,2,1))*256*2 56)+(ord(substr($data,1,1))*256)+(ord(substr($data,0,1))); and now $value contains the value of the DWORD, it works fine, but it seems that it could be done a lot easier :) Anyone experience with it? Could you not use the bitwise operator? Edward -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to convert Little-Endian DWORD to string
On 5/30/07, Edward Kay [EMAIL PROTECTED] wrote: -Original Message- From: Tijnema [mailto:[EMAIL PROTECTED] Sent: 30 May 2007 15:20 To: php Subject: [PHP] Best way to convert Little-Endian DWORD to string Hi, Maybe quite strange question and quite off topic, but there's PHP involved :) I want to read out files, and then I come across 4byte DWORD values, they are stored in little endian values, but how do I get in a PHP string (as the values are too large for integer) My code is currently this: $data = fread($fp,4); $value = (ord(substr($data,3,1))*256*256*256)+(ord(substr($data,2,1))*256*2 56)+(ord(substr($data,1,1))*256)+(ord(substr($data,0,1))); and now $value contains the value of the DWORD, it works fine, but it seems that it could be done a lot easier :) Anyone experience with it? Could you not use the bitwise operator? Edward How could I use them here? I read the docs for bitwise operators, and they tell me what they do, but now how to use it :( Tijnema -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to convert Little-Endian DWORD to string
On Wed, May 30, 2007 9:19 am, Tijnema wrote: Maybe quite strange question and quite off topic, but there's PHP involved :) I want to read out files, and then I come across 4byte DWORD values, they are stored in little endian values, but how do I get in a PHP string (as the values are too large for integer) My code is currently this: $data = fread($fp,4); $value = (ord(substr($data,3,1))*256*256*256)+(ord(substr($data,2,1))*256*256)+(ord(substr($data,1,1))*256)+(ord(substr($data,0,1))); and now $value contains the value of the DWORD, it works fine, but it seems that it could be done a lot easier :) Anyone experience with it? Easiest might be to read one byte at a time... $byte0 = fread($fp, 1); $byte1 = fread($fp, 1); $byte2 = fread($fp, 1); $byte3 = fread($fp, 1); $value = $byte3 * 0xff + $byte2 * 0x + $byte1 * 0xff + $byte0; If that makes fread too slow, which it might, but buffering should be able to handle 4 bytes... You could also do: $byte0 = 0xff00 $data; $byte1 = 0x00ff $data; $byte2 = 0xff00 $data; $byte3 = 0x00ff $data; //same $value line as above As far as shifting goes... I *think* this would do it: $byte3 = $data 24; $byte2 = ($data 16) 0xff; $byte1 = ($data 8) 0xff; $byte0 = $data 0xff; -- Some people have a gift link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to format double as money?
http://www.php.net/money_format On Saturday 05 May 2007, Todd Cary wrote: I have a MySQL DB that stores currency values as doubles. I want to display the values in the #,##0.00 format. What is the best way to do that? Todd -- Ariste Software 2200 D Street Ext Petaluma, CA 94952 (707) 773-4523 -- Larry Garfield AIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it. -- Thomas Jefferson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to format double as money?
*sigh* http://www.google.com/search?hl=enq=PHP+format+double+as+moneybtnG=Search On 5/5/07, Larry Garfield [EMAIL PROTECTED] wrote: http://www.php.net/money_format On Saturday 05 May 2007, Todd Cary wrote: I have a MySQL DB that stores currency values as doubles. I want to display the values in the #,##0.00 format. What is the best way to do that? Todd -- Ariste Software 2200 D Street Ext Petaluma, CA 94952 (707) 773-4523 -- Larry Garfield AIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it. -- Thomas Jefferson -- 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] Best way to format double as money?
I have a MySQL DB that stores currency values as doubles. I want to display the values in the #,##0.00 format. What is the best way to do that? Todd -- Ariste Software 2200 D Street Ext Petaluma, CA 94952 (707) 773-4523 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to manage open slots for download
I think you want $bytes_out = $size, actually... I'm not sure what you are sending out for that last extra byte... :-) You could consider just timing out any zombies. You could use ignore_user_abort and hope to finish most of the downloads, as far as PHP is concerned, but I don't think ignore_user_abort is 100% guaranteed, and there's always the chance of a PHP or Apache connection crashing... You could also re-think the problem to check, say, load on the server, or some sort of bandwidth meter that you could manage, rather than N slots. So somebody on a dog-slow dialup downloading would not count as much as somebody sucking down your entire bandwidth on a T-1. By shaping it by the bytes/sec being spewed out by PHP, zombie connections will naturally stop updating the meter, so won't count. On Sun, December 31, 2006 9:12 am, Aras wrote: First of all, Happy New Year for everyone in the list. I wish 2007 brings all us happiness, health and peace. I want to read your advises at a point i am stuck within, i have an application that serves downloads to clients. For some reason i am limiting total open slot for some group of users (not related to my technical question). Example; // CHECKS SLOT HERE else { // IF THERE ANY AVAILABLE SLOTS SEND THE FILE // INCREMENT SLOT NUMBER BY 1 $fp = fopen($pathside,r); if ($fp) { while (!feof($fp)) { echo fread($fp, 334); $bytes_out += 334; ob_flush(); if ($bytes_out $size) { // DECREASE SLOT NUMBER BY 1, BECAUSE THIS DOWNLOAD IS FINISHED } } } } Slots are recorded and checked from a simple mysql table. Everything works in this scenario. There is no problem if a person starts a download and finishes it, his slots get empty upon doing so. Yet if he cancelles the transfer, he will never reach my control structure to empty the slot. And slots will be full of zombies. I have thought of updating a mysql field for alive-connections in the while loop, but it will definitely add some load on my server. Updating a system file is not secure and good way. What other ways can you recommend to me for the situtation? Aras Koktas [EMAIL PROTECTED] Business Excellence Development Phi.dot Internet Systems -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to manage open slots for download
At 10:15 AM -0500 12/31/06, Rasmus Lerdorf wrote: What other ways can you recommend to me for the situtation? Read through this: http://www.php.net/manual/en/features.connection-handling.php -Rasmus -Rasmus: Just want to express my gratitude for your attendance to this list. Thanks. tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Best way to manage open slots for download
First of all, Happy New Year for everyone in the list. I wish 2007 brings all us happiness, health and peace. I want to read your advises at a point i am stuck within, i have an application that serves downloads to clients. For some reason i am limiting total open slot for some group of users (not related to my technical question). Example; // CHECKS SLOT HERE else { // IF THERE ANY AVAILABLE SLOTS SEND THE FILE // INCREMENT SLOT NUMBER BY 1 $fp = fopen($pathside,r); if ($fp) { while (!feof($fp)) { echo fread($fp, 334); $bytes_out += 334; ob_flush(); if ($bytes_out $size) { // DECREASE SLOT NUMBER BY 1, BECAUSE THIS DOWNLOAD IS FINISHED } } } } Slots are recorded and checked from a simple mysql table. Everything works in this scenario. There is no problem if a person starts a download and finishes it, his slots get empty upon doing so. Yet if he cancelles the transfer, he will never reach my control structure to empty the slot. And slots will be full of zombies. I have thought of updating a mysql field for alive-connections in the while loop, but it will definitely add some load on my server. Updating a system file is not secure and good way. What other ways can you recommend to me for the situtation? Aras Koktas [EMAIL PROTECTED] Business Excellence Development Phi.dot Internet Systems -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to manage open slots for download
Aras wrote: First of all, Happy New Year for everyone in the list. I wish 2007 brings all us happiness, health and peace. I want to read your advises at a point i am stuck within, i have an application that serves downloads to clients. For some reason i am limiting total open slot for some group of users (not related to my technical question). Example; // CHECKS SLOT HERE else { // IF THERE ANY AVAILABLE SLOTS SEND THE FILE // INCREMENT SLOT NUMBER BY 1 $fp = fopen($pathside,r); if ($fp) { while (!feof($fp)) { echo fread($fp, 334); $bytes_out += 334; ob_flush(); if ($bytes_out $size) { // DECREASE SLOT NUMBER BY 1, BECAUSE THIS DOWNLOAD IS FINISHED } } } } Slots are recorded and checked from a simple mysql table. Everything works in this scenario. There is no problem if a person starts a download and finishes it, his slots get empty upon doing so. Yet if he cancelles the transfer, he will never reach my control structure to empty the slot. And slots will be full of zombies. I have thought of updating a mysql field for alive-connections in the while loop, but it will definitely add some load on my server. Updating a system file is not secure and good way. What other ways can you recommend to me for the situtation? Read through this: http://www.php.net/manual/en/features.connection-handling.php -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to get PHP5
Jack Gates wrote: On Wednesday 09 August 2006 19:24, Jochem Maas wrote: Jonathan Duncan wrote: On Wed, 9 Aug 2006, Chris W. Parker wrote: Jack Gates mailto:[EMAIL PROTECTED] ... FUD-tastic! Jonathan Chris, Jochem just proved what I said earlier. Every one has their own preference and some go so far as to claim that the ones they just don't like are evil. That is why there are so many different flavors of Linux. That is also what will continue to hold Linux back in the market place and allow the truly evil OS to hold there market share on the desktop. I would say that's more down to billion dollar marketing budgets, anti-trust business practices and the fact that a labotomized monkey could operate Windows (where as you are at a real advantage using Linux if you have a complete brain.); not to mention that M$ is probably the largest purveyor of linux-FUD of them all. look Microsoft is doing everything it can to protect my children online**, how can linux compete with that? personally I prefer eating razor blades to using something from Redmond Washington so Bill is not your uncle then? ** 'everything' being drawing imaginary cartoon castles around some kids laptop (oh and don't forget the imaginary cartoon guard dogs) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to get PHP5
On 10/08/06, Chris W. Parker [EMAIL PROTECTED] wrote: Jonathan Duncan mailto:[EMAIL PROTECTED] on Wednesday, August 09, 2006 3:55 PM said: If you want to really learn Linux, try Gentoo. If you just want a very good and easy to use Linux, go with SuSE. To keep this related to the question I asked... Do either of the latest builds of these distros have PHP5? Why not just look? http://packages.gentoo.org/packages/?category=dev-lang;name=php http://www.novell.com/products/linuxpackages/suselinux/php5.html Although I have to say - if you're scared of compiling PHP, Gentoo's probably not the distribution for you. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Best way to get PHP5
On Wed, 9 Aug 2006, Chris W. Parker wrote: Jonathan Duncan mailto:[EMAIL PROTECTED] on Wednesday, August 09, 2006 3:55 PM said: If you want to really learn Linux, try Gentoo. If you just want a very good and easy to use Linux, go with SuSE. To keep this related to the question I asked... Do either of the latest builds of these distros have PHP5? Thanks, Chris. I just checked the Gentoo portage tree and it has PHP 5.1.4 in it already. Having it in the portage tree means it is as good as installed. I just checked the SuSE Linux 10.1 package listing and it comes with 5.1.2: http://www.novell.com/products/linuxpackages/suselinux/index_all.html The answer to your question is yes. Jonathan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to get PHP5
Chris W. Parker wrote: Hello, Generally (well, actually 100%) I just use whatever version of PHP is included with a certain distro (Redhat pre-Fedora, Fedora Core, CentOS). None of the versions I've used have come with PHP5 and I'd really like to get with the times and use PHP5. I know that Fedora Core 5 offers PHP 5.1.2 but I've heard some negative things about it in general (FC5). I've never compiled PHP myself so admittedly I'm a bit skeered... Is the recommended path to just go with whatever distro I prefer and then download PHP5 from php.net and install it myself? Virtually all distros should have php5 as an option these days. Though frequently it's named php5 rather than simply php. Debian, and probably several other distributions, only offer it in their testing branch. As a general rule I would recomend not installing from source, you can seriously damage your system with multiple versions of programs, files going in places they shouldn't and running in to dependancy hell. The distributions that I am familiar with provide packages for the php extensions so you don't have to recompile to add them. IF you do install from source, using your package management system to grab the source dependancies can simplify things significantly. On a Debian based distribution this can be done with `apt-get build-dep php5`. David -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to get PHP5
On Fri, 2006-08-11 at 00:29 +1000, David Tulloh wrote: Chris W. Parker wrote: Hello, Generally (well, actually 100%) I just use whatever version of PHP is included with a certain distro (Redhat pre-Fedora, Fedora Core, CentOS). None of the versions I've used have come with PHP5 and I'd really like to get with the times and use PHP5. I know that Fedora Core 5 offers PHP 5.1.2 but I've heard some negative things about it in general (FC5). I've never compiled PHP myself so admittedly I'm a bit skeered... Is the recommended path to just go with whatever distro I prefer and then download PHP5 from php.net and install it myself? Virtually all distros should have php5 as an option these days. Though frequently it's named php5 rather than simply php. Debian, and probably several other distributions, only offer it in their testing branch. As a general rule I would recomend not installing from source, you can seriously damage your system with multiple versions of programs, files going in places they shouldn't and running in to dependancy hell. The distributions that I am familiar with provide packages for the php extensions so you don't have to recompile to add them. U, it's pretty simplistic under linux to have mutliple versions. In fact I have every almost every version since 4.1.0 installed and easily activated. I keep a master /usr/local/php/ directory in which each version is housed and the currently active version is focused by a soft-link (I have phpWeb versions also since I compile in different features and they work under the same principle): ::/usr/local/php ls -al | grep phpCgi lrwxrwxrwx 1 root root 12 2006-07-31 14:28 phpCgi - phpCgi-4.4.2/ drwxrwxr-x 16 root root 4.0K 2004-08-25 22:20 phpCgi-4.1.0/ drwxrwxr-x 16 root root 4.0K 2004-08-25 22:20 phpCgi-4.1.1/ drwxrwxr-x 16 root root 4.0K 2004-08-25 22:20 phpCgi-4.1.2/ drwxrwxr-x 17 root root 4.0K 2004-08-25 22:20 phpCgi-4.2.0/ drwxrwxr-x 15 root root 4.0K 2004-08-25 22:20 phpCgi-4.2.1/ drwxrwxr-x 16 root root 4.0K 2004-08-25 22:20 phpCgi-4.2.2/ drwxr-xr-x 16 root root 4.0K 2004-08-25 22:20 phpCgi-4.2.3/ drwxr-xr-x 18 root root 4.0K 2004-08-25 22:20 phpCgi-4.3.0/ drwxrwxr-x 18 root root 4.0K 2004-08-25 22:20 phpCgi-4.3.1/ drwxr-xr-x 18 root root 4.0K 2005-03-23 00:03 phpCgi-4.3.10/ drwxr-xr-x 18 root root 4.0K 2005-07-16 12:55 phpCgi-4.3.11/ drwxrwxr-x 18 root root 4.0K 2004-08-25 22:20 phpCgi-4.3.2/ drwxrwxr-x 18 root root 4.0K 2004-08-20 19:23 phpCgi-4.3.3/ drwxrwxr-x 18 root root 4.0K 2004-08-20 19:30 phpCgi-4.3.4/ drwxr-xr-x 18 root root 4.0K 2005-06-24 01:41 phpCgi-4.3.5/ drwxr-xr-x 18 root root 4.0K 2004-08-20 19:37 phpCgi-4.3.6/ drwxr-xr-x 18 root root 4.0K 2004-08-20 19:40 phpCgi-4.3.7/ drwxr-xr-x 18 root root 4.0K 2004-08-20 19:43 phpCgi-4.3.8/ drwxr-xr-x 18 root root 4.0K 2005-03-23 00:02 phpCgi-4.3.9/ drwxr-xr-x 18 root root 4.0K 2006-03-13 16:41 phpCgi-4.4.0/ drwxr-xr-x 18 root root 4.0K 2006-08-05 15:03 phpCgi-4.4.2/ lrwxrwxrwx 1 root root 12 2006-07-31 14:29 phpCgi5 - phpCgi-5.1.1/ drwxr-xr-x 18 root root 4.0K 2004-08-20 19:47 phpCgi-5.0.0/ drwxr-xr-x 18 root root 4.0K 2004-04-07 11:53 phpCgi-5.0.0RC1/ drwxrwxr-x 18 root root 4.0K 2004-10-03 09:47 phpCgi-5.0.1/ drwxr-xr-x 18 root root 4.0K 2005-03-23 00:09 phpCgi-5.0.2/ drwxr-xr-x 18 root root 4.0K 2005-03-23 00:12 phpCgi-5.0.3/ drwxr-xr-x 18 root root 4.0K 2005-11-30 23:08 phpCgi-5.1.1/ Then in my /usr/local/bin/ I link to the phpCgi link... [EMAIL PROTECTED]:/usr/local/bin ls -al | grep phpCgi lrwxrwxrwx 1 root root 43 2006-07-31 16:03 pear - /usr/local/php/phpCgi/installation/bin/pear* lrwxrwxrwx 1 root root 46 2006-07-31 16:03 peardev - /usr/local/php/phpCgi/installation/bin/peardev* lrwxrwxrwx 1 root root 43 2006-07-31 16:03 pecl - /usr/local/php/phpCgi/installation/bin/pecl* lrwxrwxrwx 1 root root 42 2006-07-31 16:03 php - /usr/local/php/phpCgi/installation/bin/php* lrwxrwxrwx 1 root root 49 2006-07-31 16:03 php-config - /usr/local/php/phpCgi/installation/bin/php-config* lrwxrwxrwx 1 root root 45 2006-07-31 16:03 phpize - /usr/local/php/phpCgi/installation/bin/phpize* And the magic happens by using the following magical parameters for the configure script: --prefix=/usr/local/php/${PHP_VERSION_DIR}/installation \ --exec-prefix=/usr/local/php/${PHP_VERSION_DIR}/installation This makes it really simple to test code with any given version of PHP since all I need to do is change the softlink in the /usr/local/php/ directory. For web testing, I change the link and restart the webserver. 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
[PHP] Best way to get PHP5
Hello, Generally (well, actually 100%) I just use whatever version of PHP is included with a certain distro (Redhat pre-Fedora, Fedora Core, CentOS). None of the versions I've used have come with PHP5 and I'd really like to get with the times and use PHP5. I know that Fedora Core 5 offers PHP 5.1.2 but I've heard some negative things about it in general (FC5). I've never compiled PHP myself so admittedly I'm a bit skeered... Is the recommended path to just go with whatever distro I prefer and then download PHP5 from php.net and install it myself? Thanks, Chris. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to get PHP5
On Wed, 9 Aug 2006, Chris W. Parker wrote: Hello, Generally (well, actually 100%) I just use whatever version of PHP is included with a certain distro (Redhat pre-Fedora, Fedora Core, CentOS). None of the versions I've used have come with PHP5 and I'd really like to get with the times and use PHP5. I know that Fedora Core 5 offers PHP 5.1.2 but I've heard some negative things about it in general (FC5). I've never compiled PHP myself so admittedly I'm a bit skeered... Is the recommended path to just go with whatever distro I prefer and then download PHP5 from php.net and install it myself? Thanks, Chris. Yes, I would recommend that. If you are serious about using PHP for a while it would be benefitial to you to understand the installation aspect of the language. If you are comfortable with the command line this should be pretty easy for you. If not it will be a bit harder but still very possible. Here are installation instructions from php.net: http://www.php.net/manual/en/install.unix.php Good luck! Jonathan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to get PHP5
On Wednesday 09 August 2006 12:03, Jonathan Duncan wrote: On Wed, 9 Aug 2006, Chris W. Parker wrote: Hello, Generally (well, actually 100%) I just use whatever version of PHP is included with a certain distro (Redhat pre-Fedora, Fedora Core, CentOS). None of the versions I've used have come with PHP5 and I'd really like to get with the times and use PHP5. I know that Fedora Core 5 offers PHP 5.1.2 but I've heard some negative things about it in general (FC5). I've never compiled PHP myself so admittedly I'm a bit skeered... Is the recommended path to just go with whatever distro I prefer and then download PHP5 from php.net and install it myself? Thanks, Chris. Yes, I would recommend that. If you are serious about using PHP for a while it would be benefitial to you to understand the installation aspect of the language. If you are comfortable with the command line this should be pretty easy for you. If not it will be a bit harder but still very possible. Here are installation instructions from php.net: http://www.php.net/manual/en/install.unix.php Good luck! Jonathan Also, when compiling it yourself you can specify what extensions you want. This allows you to keep your install as minimal as possible for your needs, which increases the performance of PHP. -- Ray Hauge Programmer/Systems Administrator American Student Loan Services www.americanstudentloan.com 1.800.575.1099 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to get PHP5
Chris W. Parker wrote: Hello, Generally (well, actually 100%) I just use whatever version of PHP is included with a certain distro (Redhat pre-Fedora, Fedora Core, CentOS). None of the versions I've used have come with PHP5 and I'd really like to get with the times and use PHP5. I know that Fedora Core 5 offers PHP 5.1.2 but I've heard some negative things about it in general (FC5). I've never compiled PHP myself so admittedly I'm a bit skeered... Is the recommended path to just go with whatever distro I prefer and then download PHP5 from php.net and install it myself? Thanks, Chris. Build PHP from sourceno reason to be scared, it really is quite painless, and the docs are fairly easy to follow. (and I *believe* php 5.1.2 has some security issues, as well as none of the nice updates for the Oracle driver if you are using Oracle, so go with 5.1.4) -Brad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to get PHP5
On Wednesday 09 August 2006 12:02, Chris W. Parker wrote: I know that Fedora Core 5 offers PHP 5.1.2 but I've heard some negative things about it in general (FC5). What sort of negative things have you heard in general about (FC5)? -- Jack Gates http://www.morningstarcom.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to get PHP5
Chris W. Parker wrote: Hello, Generally (well, actually 100%) I just use whatever version of PHP is included with a certain distro (Redhat pre-Fedora, Fedora Core, CentOS). None of the versions I've used have come with PHP5 and I'd really like to get with the times and use PHP5. I know that Fedora Core 5 offers PHP 5.1.2 but I've heard some negative things about it in general (FC5). I've never compiled PHP myself so admittedly I'm a bit skeered... Is the recommended path to just go with whatever distro I prefer and then download PHP5 from php.net and install it myself? roll your own - it's easy enough, and once you have mastered it you'll have a warm fuzzy feeling - when you initially get start you might run into a bit of trouble with regard to required libs/developer files needed by certain extensions that are not installed (use your fav package manager to grab those) but the basic premise is this (at the cmdline): $ mkdir ~/some-work-dir $ cd ~/some-work-dir $ wget http://nl2.php.net/get/php-5.1.4.tar.gz/from/this/mirror $ tar -xvvf php-5.1.4.tar.gz $ cd ./php-5.1.4 $ ./configure $ make $ make test $ make install you now have a basic php build on your system 1. you can skip 'make test' 2. if in doubt do 'make clean' before 'make' 3. rinse and repeat 'configure', 'make', 'make install' as required 4. do './configure --help' to see all the options you can pass to configure 5. get stuck with a configure option (for instance enabling GD) come back here :-) Thanks, Chris.ne`qc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php