RE: [PHP-DB] include() statement hell!
I have found the best way for me is always include with the fullpath ie, include(/usr/httpd/mysite/include.inc); or: include($_SERVER['DOCUMENT_ROOT']/include.inc); Then you can include files that are elswhere: include(/usr/httpd/virtual-domain-includes/multi-user-include.inc); these will work no matter what dir or sub dir the page calling the include is in... (I haven't Followed This entire thread.. so sorry if I missed something) JD -Original Message- From: Jonathan Hilgeman [mailto:[EMAIL PROTECTED]] Sent: Thursday, March 28, 2002 10:10 AM To: 'Brad Melendy'; [EMAIL PROTECTED] Subject: RE: [PHP-DB] include() statement hell! So, maybe this is the question. Can you include a file from /main/page.php by using a path of /includes/dblib.inc? Probably not. PHP can see the whole filesystem, not just the area that is limited to your account. So, when you try to include /includes/dblib.inc it is trying to go down to the SYSTEM root and open up a subdirectory called includes and get the file dblib.inc inside it. If you copy the dblib.inc to the same directory as page.php, you should only have to say: include(dblib.inc); However, if you have this layout: /your/account/dir/main/page.php /your/account/dir/includes/dblib.inc /your/account/dir/includes/userlib.inc Then page.php would have to say: include(../includes/dblib.inc); Which would go back one directory, THEN into the includes subdirectory, and then it could find dblib.inc I would definitely add: error_reporting(2039); ...to the top of your page.php code to see if you can pick up any errors. Also, check your error log if you have one (contact your hosting company if you're not sure). I would definitely try to solve this the normal way by finding the problem with the paths rather than trying to screw with your php.ini or httpd.conf file - otherwise you'll have a script that might not work if you ever have to move your scripts or copy them to a development server or something. - Jonathan -Original Message- From: Brad Melendy [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 27, 2002 7:27 PM To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] include() statement hell! Thanks Jonathan, I'm trying to include a file /includes/dblib.inc from /main/page.php. In /main/page.php I use include(includes/dblib.inc);. When that didn't work, I tried copying the file to /main/ and including it there and that didn't work either. Finally, I tried adding a specific path to the php.ini file for includes_path and put the files there and that worked. Then I went and changed the php.ini file to remove the reference (still trying to get it to work the way I THINK it should) and then it WORKED! But ONLY from within /main/. Each time I make these changes, I am making a matching change in the actual include() statement at the top of /main/page.php and I am restarting apache each time I change php.ini. So, maybe this is the question. Can you include a file from /main/page.php by using a path of /includes/dblib.inc? dblib.inc has functions that do connections and queries to a mysql database. Even stranger yet, is that I have one other include file called userlib.inc that has authentication related session functions. Well, that hasn't worked at all no matter what, unless I put the functions in /includes/userlib.inc directly into the file /main/page.php. Once there, all the functions work fine. Otherwise, the only error messages I get are regarding unknown functions being referenced, yet, I never get an error that the include files can't be found. It's all crazy to me. Currently, both of my include files are called directly with two lines like: include(dblib.inc); include(userlib.inc); They are both located in /main/ along side page.php which is calling them. They both seem to work this way, but as soon as I place them in /includes/ and try to call them using: include(includes/dblib.inc); include(includes/userlib.inc); I get errors saying that the functions can't be found, however, no errors saying it can't find the include files?? Lastly, even with both include files in /main/ I still have some strange problem with my userlib.inc file because the single function that is in there won't work unless the function is pasted directly into /main/page.php. I think I've made this message way too long but I appreciate your help. I've got the page working reliably with the functions all pasted into page.php but not while including those functions. I just can't think of what could be making it difference. The functions are all the same, just running from an include file is a problem. Thanks again, just writing this up has helped to make more sense to me. I think the crux of the whole thing is the path. I'm using to including files in ASP and those can be relative so something like ../includes/dblib.inc works great. ...Brad -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] I'm really stuck!
Try doing echo stripslashes($data); Or try setting the content type to text/plain - This should echo back gobblygook (Just so you know that there IS image data there. Also.. you have img src=\petdata.php?id=$id\ in another file right? If you call petdata.php by itself, you should see just the image. JD -Original Message- From: Jennifer Downey [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 28, 2002 4:41 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] I'm really stuck! Hi all, I'm really stuck and I'm not asking anyone to re-write this just show me what is wrong, or explain why it wont work. It just seems logical that this should work. The first query will print the pet id in the browser. $query=SELECT id FROM wt_users WHERE uid={$session[uid]}; $ret = mysql_query($query); while(list($pet)= mysql_fetch_row($ret)) print(BRyour pet id is $pet); So if $pet will print the id from the wt_users (has a value of 3) and I assign $id = $pet (id also has a value of 3 in image_data) why doesn't it show the image? if($id) { $id = $pet; $query = select bin_data,filetype from image_data where id=$id; $result = mysql_query($query); $data = mysql_query($result,0,bin_data); $type = mysql_query($result,0,filetype); Header( Content-type: $type); echo $data; }; echo img src=\petdata.php?id=$id\; Thanks Jennifer Downey -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Re: A good tutorial
I am just going to interject a second here... sorry :P About storing images on a server... I did that for awhile, but once i hit 1000+ images, my scripts started timing out.(from reading the directory) Storing them in the DB seems to actually improve performance for php... Another issue is that I have one copy of a php script in my apache site root folder, and use aliases to install the same script on many domains (Using VirtualHost containers in httpd.conf) I have gone back and forth from one system to another, and haven't found a perfect solution yet :) JD -Original Message- From: Lerp [mailto:[EMAIL PROTECTED]] Sent: Tuesday, February 19, 2002 12:20 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Re: A good tutorial Hi Jen, here's some code I posted up in the general ng for storing in db and retrieving images from db for display on your page. It's recommended that you stay away from storing actual images in the db. If you are storing a path the code below might help you out. It select a firstname, and an image according to an id. You'll have to change the youridentityfield and youridentity values to suit your needs. # display image from db # #connect to db $connectionToDBid = odbc_connect(ceo34deesnr43ipits, joeyscode, joeyscode); // sql statement $sqlb = SELECT imagepath, firstname FROM IMAGES WHERE youridentityfield = . $youridentity; # execute the query $resultset = odbc_do($connectionToDBid, $sqlb); $image = odbc_result($resultset,1); $firstname = odbc_result($resultset,2); print brbrbrdiv align='center'; print table width='400' border=0 cellpadding=2 ; print trtd align='left' ; print font color='#ff' face='verdana'h4 . Welcome back . $firstname . /h4/font; print /td/tr; print trtd align='center' ; print img src=' . $image.' align='center' border='0'br; print /td/tr; print /table; # close the db connection here # end of display image from db # #photo upload form Here's a common form that allows you to upload a file (say an image) to the db form action='upload.php' method='post' enctype='multipart/form-data' input type='hidden' name='MAX_FILE_SIZE' value='102400' Pfont color='#ff' face='verdana' size=1Upload Photo:/fontinput type='file' name='userfile'input type='submit' value='Upload!!!'/form/p end of photo upload form ## start of upload process to db ?php # $userfile is the file being uploaded # print $userfile . BR; # print $userfile_name . BR; #use a time stamp plus the original file name to uniquely name the image before storing in db to prevent two files with the same name $timestamp = time(); $userfile_name = $timestamp.$userfile_name ; // copy the file being posted -- remember to escape backslashes!!! if(copy($userfile, /ez/codesnipits/consultant/tempimages/. $userfile_name)){ print font face='Verdana, Arial, Helvetica, sans-serif' color='#663399' size='2'Your picture has been uploaded successfully and has been made available for online users to view./fontbrbrbr ; } else { print font face='Verdana, Arial, Helvetica, sans-serif' color='#663399'Error encountered during resume upload process./fontbr; } $patharola = tempimages/. $userfile_name; // insert path into database here # connect to db $connectionToDBid = odbc_connect(cdefc5onwesulertt, joeyscon, joeyscon); session_register(consultantid); $consultantid = $consultantid; # create query statement -- update image field in db using path $sqlr = UPDATE CONSULTANT SET image= '$patharola' WHERE consultantid= . $consultantid; # execute the sql statement (query) on the connection made $resultset = odbc_do($connectionToDBid, $sqlr); ? end of image to db process ## Hope this helps you out :) Cheers Joe :) Jennifer Downey [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... If anyone knows of one, would someone please point me towards a good tutorial on storing images in a database then fetching them out again. I would really appreciate it and thanks in advance! Jen Downey -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Re: A good tutorial
It has never timed out bringing back from the db... only when reading from disk. I think the big difference is I need to create both fancy web pages and neat printable pages. So I need to open up an image stream to manipulate the photo. I had a top level dir called photos, then a sub folder named from the row id in the MySQL table.. so the path was always something like /photos/1066/photo.jpg once I hit 1000+ records (thusly, 1000+ sub dirs in photos/) ... it would time out opening the 1066 directory. (displaying 15 records at a time) It is much faster now with a separate table with binary data and storing just the id for an image in the original table... then just select using an id. ( a separate select staement seems to be faster than joining the tables) The biggest problem tho was that I have two servers working as web farms. if one domain needed access to the photos from another domain located on the other server, I could not open the photos. (For resizing and such) When they are in the db, I can get them from anywhere. JD -Original Message- From: Joe Van Meer [mailto:[EMAIL PROTECTED]] Sent: Tuesday, February 19, 2002 3:04 PM To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Re: A good tutorial Hi again JD...I got to thinkin':) Just out of curiosity...how many images were you bringing back from the db when your script timed out? I store the path of my image in the db and echo it out when I need to. Cheers Joe:) Jd Daniels [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I am just going to interject a second here... sorry :P About storing images on a server... I did that for awhile, but once i hit 1000+ images, my scripts started timing out.(from reading the directory) Storing them in the DB seems to actually improve performance for php... Another issue is that I have one copy of a php script in my apache site root folder, and use aliases to install the same script on many domains (Using VirtualHost containers in httpd.conf) I have gone back and forth from one system to another, and haven't found a perfect solution yet :) JD -Original Message- From: Lerp [mailto:[EMAIL PROTECTED]] Sent: Tuesday, February 19, 2002 12:20 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Re: A good tutorial Hi Jen, here's some code I posted up in the general ng for storing in db and retrieving images from db for display on your page. It's recommended that you stay away from storing actual images in the db. If you are storing a path the code below might help you out. It select a firstname, and an image according to an id. You'll have to change the youridentityfield and youridentity values to suit your needs. # display image from db # #connect to db $connectionToDBid = odbc_connect(ceo34deesnr43ipits, joeyscode, joeyscode); // sql statement $sqlb = SELECT imagepath, firstname FROM IMAGES WHERE youridentityfield = . $youridentity; # execute the query $resultset = odbc_do($connectionToDBid, $sqlb); $image = odbc_result($resultset,1); $firstname = odbc_result($resultset,2); print brbrbrdiv align='center'; print table width='400' border=0 cellpadding=2 ; print trtd align='left' ; print font color='#ff' face='verdana'h4 . Welcome back . $firstname . /h4/font; print /td/tr; print trtd align='center' ; print img src=' . $image.' align='center' border='0'br; print /td/tr; print /table; # close the db connection here # end of display image from db # #photo upload form Here's a common form that allows you to upload a file (say an image) to the db form action='upload.php' method='post' enctype='multipart/form-data' input type='hidden' name='MAX_FILE_SIZE' value='102400' Pfont color='#ff' face='verdana' size=1Upload Photo:/fontinput type='file' name='userfile'input type='submit' value='Upload!!!'/form/p end of photo upload form ## start of upload process to db ?php # $userfile is the file being uploaded # print $userfile . BR; # print $userfile_name . BR; #use a time stamp plus the original file name to uniquely name the image before storing in db to prevent two files with the same name $timestamp = time(); $userfile_name = $timestamp.$userfile_name ; // copy the file being posted -- remember to escape backslashes!!! if(copy($userfile, /ez/codesnipits/consultant/tempimages/. $userfile_name)){ print font face='Verdana, Arial, Helvetica, sans-serif' color='#663399' size='2'Your picture has been uploaded succ
RE: [PHP-DB] Converting upper case letters to lower case because of db??
strtolower() -Original Message- From: Andy [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 07, 2002 8:08 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] Converting upper case letters to lower case because of db?? Hi there, I have a tabel with 250 entries showing a country code lik CA Now my application does not work on linux, because they have to be in lower case. Can I make anyhow an bufix, or even better creating a php function to change all 250 entries to lower case. I could not find the propper function on the php site. Can anybody please help on changing this thing into lower case? Thanx ANdy -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Viewing Session Varibles
Like so: echopre; print_r($_SESSION); echo/pre: I think for PHP less 4.04, you need $HTTP_SESSION_VARS Instead. JD -Original Message- From: Robert Weeks [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 07, 2002 8:45 AM To: php Subject: [PHP-DB] Viewing Session Varibles Is there an easy way to get a dump to the page of all session varibles? I'm trying to create an associtave array in a session varible named cart ($item1 =$qty1, $item3=$qty2, etc.) and i can't seem to wrap my brain around it this morning. I get the item set but can't get the $qty to set. Thanks, Robert Weeks -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Viewing Session Varibles
hmmm... If I was you.. I would make your cart an object.. build a simple class like: class Cart { var $items; function Cart() { $this-items=Array(); } function Add_To_Cart($item) { if(!in_array($item,$this-items) { Array_Push($this-items,$items; } } function Remove_From_Cart($item) { if(in_array($item,$this-items) { unset($this-item[$items); } } } So in your script: session_start(); if (!session_is_registered(cart)) { $cart = new Cart; session_register(cart); } /* now you should be able to get everything like this */ $cart-Add_To_Cart($whatever); $cart-Remove_From_Cart($whatever); /* where $whatever is the array of item data... first of which would be the id */ then you can manipulate it how ever you like.. just make the function inside the cart clas and call it by $cart-function_name(); This way the only thing stored in the session is the object.. which contains it all in place you can handle it. This is the only way I got reliable use out sessions :p I just whipped this off the top of my head.. so may not work :) JD -Original Message- From: Robert Weeks [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 07, 2002 10:41 AM To: php Subject: Re: [PHP-DB] Viewing Session Varibles Ok, This is driving me nuts. I'm sure its something simple but I can't seem to find the glitch. I'm trying to make a simple shopping cart using Session varibles to store the item = quantity pairs, then I loop thru the cart and query the db to get the item details, etc.. Most of it works fine but whenever I add a new item to the cart I lose the $qty value for the other items. Here is the code in question: ++ ? session_start(); include 'inc/common.inc.php'; if (!session_is_registered(cart)) { $cart = array(); session_register(cart); $items = 0; session_register(items); } if($cart[$new]) { $cart[$new]++; }else{ $cart[$new] = 1; } foreach ($cart as $id = $qty) { if ($$id == 0) { unset ($cart[$id]); }else{ $cart[$id] = $$id; } $items = calculate_items($cart); foreach ($cart as $id = $qty){ $db = mysql_connect(localhost, $databaseuser, $databasepasswd) or die (Unable to connect to database!); mysql_select_db ($databasename,$db) or die (Unable to connect to database $db!); $result = mysql_query (SELECT * from products WHERE id = '$id') or die (Error in query. . mysql_error()); if ($result){ extract(mysql_fetch_array($result)); echo bTitle:/b $titlebr /; echo bDescription:/b $p_descbr /; echo bPrice:/b $pricebr /; echo bQuantity:/b $qtybr /; echo hr /; } } #print varibles to screen for debugging echopre; print_r($HTTP_SESSION_VARS); echo/pre; ? + If one item is in the cart I get this from the $HTTP_SESSION_VARS: Array ( [cart] = Array ( [10] = 12 ) [items] = 12 [total_price] = 0.00 ) That would indicate to me that the cart pair has been saved. But as I add items I lose the earlier quantities: Array ( [cart] = Array ( [10] = [16] = [13] = 6 ) [items] = 6 [total_price] = 0.00 ) The $id is still there and I can query the db just fine, but no quantity. I don't know why this is eluding me but any help would be greatly appreciated. Thanks, Robert -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] File Uploading... Two problems...
I believe when PHP saves a file, it is already owned by the web server user. In my case, nouser. I could not get this behaviour to change. Normally you should not need to CHMOD or CHOWN anything you upload unless you need them to be modified by ftp users as well. Just make sure the folder is writeable by the web server user. (Preferably not by anybody else... 777 is all bad :) If you do end up CHMODing: On SCO, the CHMOD command did not behave like I expected it to... adding the umask made it all good... ie, $rand_name=generate_filename(,jpg) //Save The Uploaded File To Disk @copy($image, /home/sites/madden.williamsen.net/web/recruiter/resumes/$rand_name) or die(Couldn't Save File $image to $rand_name); (Note beginning slash... Robert helped you there :) //Give It Perms umask(0); chmod(/home/sites/madden.williamsen.net/web/recruiter/resumes/$temp_name,0 600); (on my SCO box, 600 is the default perms anyway ) Here is my little funtion I use to generate file names: (It is not mine.. but I cant remember who gave it to me :) function generate_filename ($len = 8,$ext) { $nps = ; mt_srand ((double) microtime() * 100); while (strlen($nps)$len) { $c = chr(mt_rand (0,255)); if (eregi(^[a-z0-9]$, $c)) $nps = $nps.$c; } $nps.=.$ext; return ($nps); } Of course, depending on what you are doing, completely random names may be useless... I save them as temporary files to resize them and save them in a DB with the regular name with special chars stripped out. JD -Original Message- From: Robert Weeks [mailto:[EMAIL PROTECTED]] Sent: Tuesday, February 05, 2002 7:19 AM To: Todd Williamsen; [EMAIL PROTECTED] Subject: Re: [PHP-DB] File Uploading... Two problems... On 2/5/02 9:58 AM, Todd Williamsen [EMAIL PROTECTED] wrote: Now I have two small issues... 1. How would I automate the file naming otherwise errors will fly (can't copy file... blah blah) You could replace the file name with a randomly generated number. There are a number of ways to generate random numbers in PHP. Try this for starters: http://www.php.net/manual/en/function.mt-rand.php 2. The second part is the most annoying. It seems that I cannot get the script to put the files into a directory I specify only where the script resides. I thought it was a permission issue, but the folder has been chmod to 777 and it still won't do it... You need the path from root to the directory. Now you have: home/sites/madden.williamsen.net/web/recruiter/resumes/$img1_name You need a forward slash before home: /home/sites/madden.williamsen.net/web/recruiter/resumes/$img1_name Instead of using chmod 777 (ick!) you should change the ownership of the file to be owned by the web server user which is usually nobody you can do this with the chown command from the command line. Robert Directory structure home web recruiter --- folder where the scripts reside resumes -- the destination where I want the uploaded files to reside here is the code... ? // if $img_name isn't empty, try to copy the file if ($img1_name != ) { // copy the file to a directory or //die and print an error message // NOTE! if you're on a Windows machine, // use Windows pathnames, like so: // copy($img1, C:\\some\\directory\\path\\$img1_name); copy($img1, home/sites/madden.williamsen.net/web/recruiter/resumes/$img1_name) or die(Couldn't copy the file!); } else { // if $img_name was empty, die and let us know why die(No input file specified); } ? thanks -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] 'htaccess method : how to modify passwords from PHP scripts ?
That is where I got the class originally... The url for the guys who wrote the class is here: http://www.thewebmasters.net/ They have a link right on the front page. There are actually two classes.. htgroup and htpasswd... I have put them into one file for my own use. Sorry to everyone for the confusion. JD -Original Message- From: Caleb Walker [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 25, 2001 6:56 PM To: JD Daniels; Samuel Torton Cc: php Subject: Re: [PHP-DB] 'htaccess method : how to modify passwords from PHP scripts ? On Tuesday 24 July 2001 10:22 am, JD Daniels wrote: There is a fantastic class that takes care of writing .ht* files... look here: http://phpclasses.upperdesign.com/ Couldnt find anything on writing .ht* files. Are you sure? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Advice On Building Dynamic MySQL Queries
Thanks for the replies :) Victor's suggestion put me on the right track. (I still have trouble with language constructs) Heres what I have now.. All I need to do is name my form fields with the same name as the column names from the mysql table, and presto! now I can just add/remove from the search form without changing the code. (I hope.. It has worked so far). while (list ($key, $val) = each ($HTTP_POST_VARS)) { if (!is_int($key) $key!="Submit" $key!="submit" $key!="offset") { if (!empty($val)) { if (!empty($whereclause)) { if($key=="Price") { $whereclause.=" AND Price$val"; }else{ $whereclause.=" AND $key='$val'"; } } else { if($key=="Price") { $whereclause.=" Price$val"; }else{ $whereclause.=" $key='$val'"; } } } } } Thnaks JD -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]