Re: Re: Uploading Photos to MySQL
| From: | Mike Gifford | Date: | Thu, 13 Sep 2001 05:53:47 +0000 |
| Subject: | Re: Re: Uploading Photos to MySQL | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-67144@lists.php.net to get a copy of this message | ||
Hi Sean,
Sorry for the delay with this.. Been a rather busy month.. However your help on this project has been very useful..
Sean C. McCarthy wrote:
Mike Gifford wrote:It is good to look at this code (not sure if Mozilla under Linux didn't like the javascript, but glad others could see it). You are right in that there are no blob files in it.. However, i wasn't starting from that file. Rather from a phplib class that was posted right here: http://circle.ch/scripts/Sean C. McCarthy wrote:I'll send you the code at a separate message, but just look at the tables definitions. There are no blob columns.If you mean http://www.webtechniques.com/archives/1998/02/lerdorf/ what inserts in the DB is just the image's name, but not the file itself.I had trouble opening up the upload.php3 file in list six, so I couldn't verify by looking at the code. Not sure if it was the javascript or what, but I couldn't open it.
I shouldn't need to use this command should I? http://php.net/manual/en/function.addcslashes.php I've used stripslashes before effectively in other pieces of code..Correct! I tried the same but with PDF files. The problem I had was that stripslashes and stripcslashes were not working as the manual said. When I had one \ addslashes() gave me \\ (comfirmed at the DB) but stripslashes() gave me a big nothing striping everything.What is exactly the problem you are having with the class? Just a couple days ago I had a problem uploading files into a MySQL DB because the addslashes function. As I have seen in this code it also uses it. Your problem is with getting corrupt data from the DB?Add slashes are included as the file is added to the array: $this->daten["image"] = addslashes(fread(fopen($userfile, "r"), filesize($userfile))); Some content almost gets inserted. However it only gets as far as:Content-Type: image/jpeg ÿØÿàThe image filed is just a blob
If it is this use base64_encode and base64_decode. This is a tip Chris (only know his name) gave me as no solution for addslashes was given... Thanks again Chris!!Ok.. This is getting better.. http://php.net/manual/en/function.base64-encode.php $this->daten["image"] = addslashes(base64_encode(fread(fopen($userfile, "r"), filesize($userfile))));
Just $this->daten["image"] = base64_encode(fread(fopen($userfile, "r"), filesize($userfile)));Ok.. I've modified this..
The special chars in RFC2045 are from
http://www.ietf.org/rfc/rfc2045.txt?number=2045 :
tspecials := "(" / ")" / "<" / ">" / "@" /
"," / ";" / ":" / "\" / <">
"/" / "[" / "]" / "?" / "="
; Must be in quoted-string,
; to use within parameter values
Ok "_" is not there... but anyway you are not going to make searches
with " ... like 'something_' ...".
Must admit that I've been thrown by this one.. I've got no idea what's up with this..
You are right.. I had commented this out because I was getting an error that the header was already loaded.. I figured since I saw that in the database as well that it had been inserted and was now redundant.gives me quite a lot more information. Even looks like when I upload different images, that it is different information (unlike previous attempts) Unfortunately, it still isn't producing the graphic that I'm looking for... Hmm.. I get raw code easily enough: http://pgs.ca/WLP/profiles/getimage-simple.php3?imageID=16 http://pgs.ca/WLP/profiles/getimage-simple.php3?imageID=17 http://pgs.ca/WLP/profiles/getimage-simple.php3?imageID=18 Which is generated by: mysql_connect($DBHOST, $DBUSER, $DBPASS); mysql_select_db($DATABASE); $resultset = mysql_query($query); $query = "SELECT image FROM ztpv_images WHERE imageID = $imageID"; $resultset = mysql_query($query); print(stripslashes(base64_decode(mysql_result($resultset, 0, "Image")))); So I couldn't either view the file here.. or within a <SRC="">. See:Have you forgot to add: header ("Content-Type: image/jpeg");http://pgs.ca/WLP/profiles/test.html
just before the print? If you have the type will be text/plain (or text/html or something). Add it just before anything gets outputed.So you want the new code to look like this (for what is now http://pgs.ca/WLP/profiles/getimage-simple.php3): mysql_connect($DBHOST, $DBUSER, $DBPASS); mysql_select_db($DATABASE); $resultset = mysql_query($query); header("Content-type: image/jpeg"); $query = "SELECT image FROM ztpv_images WHERE imageID = $imageID"; $resultset = mysql_query($query); print(base64_decode(mysql_result($resultset, 0, "Image"))); Hadn't done the following before:
doing a wget -s I got the replies from your scripts like: Content-Type: text/html Content-Type: image/jpeg ???? No idea about this...Seems like taking out the add/remove slashes has elminated it from here: [mike@office admin]$ wget -s http://pgs.ca/WLP/profiles/getimage-simple.php3?imageID=20 --01:47:53-- http://pgs.ca:80/WLP/profiles/getimage-simple.php3?imageID=20
=> `getimage-simple.php3?imageID=20'Connecting to pgs.ca:80... connected! HTTP request sent, awaiting response... 200 OK Length: unspecified [image/jpeg]
0K -> .......01:47:53 (38.18 KB/s) - `getimage-simple.php3?imageID=20' saved [7468] The image size is about right.. I thought it was 7440 (according to netscape when I uploaded it).. Not sure why it would be bigger.. Mike -- Mike Gifford, OpenConcept Consulting, http://openconcept.ca Offering everything your organization needs for an effective web site. Regarding Sept 11, http://www.fgcquaker.org/statement091101.html In all things it is better to hope than to despair.Wolfgang von Goethe