开发者

How to link images with records from the database?

开发者 https://www.devze.com 2023-03-16 16:02 出处:网络
My site is having much profiles, 开发者_如何学JAVAeach profile has afew images. Users upload this images themselves. I need to link images from disk and profiles in MySQL table. Tell mebest way to rea

My site is having much profiles, 开发者_如何学JAVAeach profile has a few images. Users upload this images themselves. I need to link images from disk and profiles in MySQL table. Tell me best way to realize this functionality for more flexibility?

ps I'm using CodeIgniter 2 + MySQL.


As you are using CodeIgniter. I assume that you are using the File Uploading Class.

After successful completion of upload, you can use

$this->upload->data()

Which basically returns an array which contains all the data related to the upload. example array

Array
(
    [file_name]    => mypic.jpg
    [file_type]    => image/jpeg
    [file_path]    => /path/to/your/upload/
    [full_path]    => /path/to/your/upload/jpg.jpg
    [raw_name]     => mypic
    [orig_name]    => mypic.jpg
    [client_name]  => mypic.jpg
    [file_ext]     => .jpg
    [file_size]    => 22.2
    [is_image]     => 1
    [image_width]  => 800
    [image_height] => 600
    [image_type]   => jpeg
    [image_size_str] => width="800" height="200"
)

Its better to store these details into database, along with the user ID to which the image belongs. And when you want to retrieve the images, just make query where the user id = someint ..

I think this solution is better than storing images in the DB.


Here is a tutorial for storing images in MySQL using PHP:

http://forum.codecall.net/php-tutorials/6937-tutorial-storing-images-mysql-php.html

0

精彩评论

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