views:

66

answers:

6

I need a simple code to upload images to mySQL using PHP... short! snippet... and is it possible to upload an html, css file to mySQL?... its reason is complicated but all answers are appreciated!... EDIT:: say I have 1000 users.. and they each have their own layout for their page.. So inside their MYSQL record will be a html file, css file(possibly), and image(s)...

A: 

Are you asking how to store a file in the database?

http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading-files-to-mysql-database.aspx

Or do you need to know how to upload a file to your web server in order to display it in a PHP/MySQL website?

iKnowKungFoo
I know how to upload files ect... I need SOME of them INSIDE the MYSQL database.. for instance.. I have 1000 users.. and they each will have their own layout for their page.. So inside their record will be a html file, css file(possibly), and image(s)... get the idea? Thanks for the link.. helps alot!
Luke3butler
A: 

You can look at this link > http://www.weberdev.com/get_example-3688.html

TeknoSeyfo
A: 

Your page would be faster, if you generate a directory on your filespace for each user and store their css/js/image files there.

The reason for this is, that when you like to output your images to the browser, you will need to establish an own db connection for each file (since each is an own HTTP request to a PHP file, selecting the image).

JochenJung
I see.. ya.. well the only problem with that is that whenever I get another user I would have to create another file set.. have any automated ideas?
Luke3butler
You could automate the file creation...There are functions in PHP like mkdir() and fopen()
JochenJung
uhhu.. thanks.. I guess i will go with a filesystem... now just how to do it with the least amount of effort...
Luke3butler
+2  A: 

I am a big fan of using a filesystem for storing physical files, i've yet to see any solid reason why they are better off in a database.

To automate this process you could have a shell script called through exec

exec("/home/some/path/my_filesystem_creator.sh ".escapeshellarg($args));

or PHP's native mkdir or anything really. If you went for a structure like:

/common/
/userdirs/1/
/userdirs/2/

essentially all i would imagine you would need to do is create a user dir, and copy into it the default versions of their site assets - images/css/html etc.

This should be easy enough to manage

seengee
I am too.. i would rather use a filesystem... how would you suggest I automate a directory/file creation? i would have a basic template that can be copied I guess... but how would you suggest doing it? have any links?
Luke3butler
simple option above
seengee
perfect... thanks!
Luke3butler
A: 

You might want to take a look at http://mysqldump.azundris.com/archives/36-Serving-Images-From-A-Database.html and http://hashmysql.org/index.php?title=Storing_files_in_the_database before doing that. Storing files in mysql is generally considered a bad idea.

shesek
A: 

Just use different CSS rules for each user. Create the CSS dynamically though PHP based on user-specific variables. For example, if they have a div with an avatar or some other personal image, just create a class that uses variables for images, and then you really only need one or two files at most to do the whole thing. I would use a heredoc, but you could just use quotation marks to integrate the PHP.

php creates your css - .useravatar{ 'background: url($baseurl.$urseridpic)'}

In the html, the div just needs the class of 'useravatar' never needing to be changed.

hyperlexic