Problems with File Upload

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

metal
Forum Newbie
Posts: 10
Joined: Wed May 02, 2007 9:07 am
Location: UK

myblobs

Post by metal »

yes the blobId is auto_increment
User avatar
arturm
Forum Commoner
Posts: 86
Joined: Fri Apr 13, 2007 8:29 am
Location: NY
Contact:

Post by arturm »

mysql is case sensitive so Myblobs myBlobs and myblobs are different tables.
metal
Forum Newbie
Posts: 10
Joined: Wed May 02, 2007 9:07 am
Location: UK

blobs

Post by metal »

I have changed it from myBlobs to myblobs and I am still recieving the message "Could not add file to the database" :(
User avatar
arturm
Forum Commoner
Posts: 86
Joined: Fri Apr 13, 2007 8:29 am
Location: NY
Contact:

Post by arturm »

change your code to:

Code: Select all

mysql_query($dbQuery);
echo mysql_error();
we will see what error do you have
metal
Forum Newbie
Posts: 10
Joined: Wed May 02, 2007 9:07 am
Location: UK

Post by metal »

I typed in the coding and the following message was returned:

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '³Ù0' at line 1"

I am unsure what this means!!!
User avatar
arturm
Forum Commoner
Posts: 86
Joined: Fri Apr 13, 2007 8:29 am
Location: NY
Contact:

Post by arturm »

it means that file content breaks mysql query.
To avoid that use base64_encode() function before inserting image to the database and base64_decode() before displaying it on a page.
metal
Forum Newbie
Posts: 10
Joined: Wed May 02, 2007 9:07 am
Location: UK

Post by metal »

I'm afraid thats abit more technical then I'm used to. Do you mean I should insert base64_encode() function just before the INSERT and base64_decode() in my script at some point after that? Also it is written reports I am adding to my database, would this make it any different than inserting a image?

This is my first attempt with PHP so I still have a mountain to climb with it!!!!
User avatar
arturm
Forum Commoner
Posts: 86
Joined: Fri Apr 13, 2007 8:29 am
Location: NY
Contact:

Post by arturm »

do that:

Code: Select all

$file_contents = base64_encode(file_get_contents($_FILES['fileUpload']['tmp_name']));
and somewhere later in code when you take data from the database and you display your image
instead

Code: Select all

echo $file_contents;
you have to do

Code: Select all

echo base64_decode($file_contents);
metal
Forum Newbie
Posts: 10
Joined: Wed May 02, 2007 9:07 am
Location: UK

Post by metal »

Thank you very much, that has worked. The file size is now showing as 26.0 KB instead of 0KB!! Now all I have to do is figure out how to download it :lol:

Thanks again, it has been much appreciated!!
Post Reply