Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Uploading images/other binaries to MySQL via PHP

Posted by admin (Graham Ellis), 10 September 2007
An excellent question here (via email) from a correspondent who needs to upload pictures for his shop site and found my example on our web site

Quote:
Hello looking around for a web site picture upload manager i found a code which your mail was under .

i am curently using a template inwhich i cant upload image products throught a wizard .

i found your 's it seems great  but i do not khow how to make it work .

if you can't help me it will be great

i do have a my sql  and i  have a tmp with yahoo web hosting.

i am currently using PHP language,


The question is not a new one ... so I thought it worthwhile pulling all my resources into one place and answering fully ...

The script you have found puts together many different aspects of http, PHP and MySQL - although it is short, it is not simple and it is not intended as a script for newcomers.   You'll see a lot of comments submitted by people saying how great it is, but a few saying that they cannot get it to work and that's because there are server settings to make, such as directories, passwords, etc - and probably URLs to change too.

I won't know exactly which page you found, but the complete example comprises the following pages

Article on subject
Running example
Looking at uploaded images
Sourec code - viewing
source code - upload

Have a look through all of these pages - the first link especially which has tips and instructions at the bottom of it and which answer most of the common questions.   Take it step bt step - see if you can get the form up with the same tags in the HTML as mine, then if you can get the temporary file onto the server, then into the database.  Finally test if you can get it back.  Splitting your problem down will help you find where it is.

If the description above leaves you asking "how do I do THAT?" then you're probably not yet at the stage to be comfortably working with the script and should learn some more basic stuff.   I would normally recommend our course (running next week!) at http://www.wellho.net/course/phfull.html  or thath you drop by one evening, but I suspect that you're not from the same part of the world that we're in; you should, then, be able to find someting along the same lines in your area.

I'll finish we another, simpler, example that uploads .pdf files ... you may get some additional clues from these pages:

Commentary
Upload form - source
Store script - source
View script - source

Graham



Posted by keith (keith), 8 November 2008
Suggestion...don't put files into MySQL as this will bloat the database..just put the link/url in mysql.
If you want to protect the images, put them outside the document root and allow php to grab them.

Posted by admin (Graham Ellis), 8 November 2008
on 11/08/08 at 04:32:25, keith wrote:
Suggestion...don't put files into MySQL as this will bloat the database..just put the link/url in mysql.
If you want to protect the images, put them outside the document root and allow php to grab them.


There are arguments both ways, Keith ... there's going to be bloat somewhere and I prefer to bloat my databases (which are designed for that sort of thing) rather than to bloat directories with thousands and thousands of individual files.   I also prefer to have them in my database as it enforces a unique accessor, rather than risk people finding / changing / deleting files directly on the file system and not appreciating the database connection.  Think of someone deciding that a file name is mis-spelled and renaming it ... not realising that the database refers to it by name. Result - one broken database!



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho