开发者

mySQL images upload

开发者 https://www.devze.com 2023-01-06 19:16 出处:网络
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 complicat开发者_如何学Pythoned but all answers a

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 complicat开发者_如何学Pythoned 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)...


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


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?


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).


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消