Solved

How to attach image(s) to Mysql record...

Posted on 2009-04-09
10
445 Views
Last Modified: 2013-11-05
I need some ideas and hopefully some link/source, etc. on how to attach images to a MYSQL database record.

Essentially I think what I want to mimic is a contact management system that will allow registered users the capability to add image(s) to a particular record in a MYSQL database. Using a thumbnail(s) or photo strip would be perfect if it would allow the user to click on the thumbnail and view a larger image.

I'm open to ideas here just remember that the user will need to attach the image(s) to a particular record in the DB. I'm using Dreamweaver so PHP, AJAX, etc. are possibilities...

Thanks.

NG,
0
Comment
Question by:nike_golf
  • 5
  • 4
10 Comments
 
LVL 6

Expert Comment

by:Thomas Wheeler
ID: 24111574
0
 
LVL 13

Author Comment

by:nike_golf
ID: 24114770
Thanks for the link.

Since the above process loads the actual image into the DB I'm a a bit concerned about file sizes. Can you do something similar using a link to the picture, also how would you handle multiple pictures?

Assuming I would like the user to be able to load 2-3 pictures how would that be achieved?

Thanks,
0
 
LVL 1

Expert Comment

by:PHPeZ
ID: 24118035
Hi,

I'd use a table to store the image names, say tbl_userImages, and whenever the user would upload an image,

> the file would be moved to a folder on the server (you must be familiar with php function like move_uploaded_file(); ..you can even look it up in the php manual if you're not sure about it).

> once the file is moved, an insert operation into tbl_userImages to keep track of the image and that data which would distinguish between which user uploaded the image (say, userId or anything that's unique in the user table)

> note that, if you're uploading on a remote web server, you need to have a folder created on the webserver with '777' level access to that folder.

Cheers!
0
 
LVL 13

Author Comment

by:nike_golf
ID: 24126774
I don't think the first option works as it doesn't seem to have an option for multiple pictures unless of course you know ahead of time how many you want to attach.

The second options seems realistic but I'm not sure about how to implement... how would I handle a user that would need to upload multiple pictures - all that I can find are tutorials on uploading a single picture?

NG,
0
 
LVL 1

Expert Comment

by:PHPeZ
ID: 24126935
Is the number of upload(s) fixed or is the user allowed to upload as much as s/he'd want ? I need to know this to help you out.
eg. the user can upload a max of 10 or simply "just 5" etc.
     or infinitely?
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 13

Author Comment

by:nike_golf
ID: 24127051
I would say it would be limited to a max of 5 images... my thoughts are to allow the user to attach multiple images to their profile/record and after the upload somehow show a small image of the images they have uploaded maybe in a picture tab strip or something...

I can't imagine nobody's done this before so any help or insight you can shed would be greatly appreciated.

NG,
0
 
LVL 1

Expert Comment

by:PHPeZ
ID: 24127070
I'm totally overburdened with projects at the moment. So sorry that I am not able to post a helpful code from one of my proj's due to that.
But I've one link here which could help you out I'm sure. [please fix the spaces :) ]
http: / /www. phpeasystep.com/workshopview.php?id=2

This will help I'm sure.
Cheers!
0
 
LVL 1

Expert Comment

by:PHPeZ
ID: 24127074
Oh! It takes url! Here's it again:
http://www.phpeasystep.com/workshopview.php?id=2
0
 
LVL 13

Author Comment

by:nike_golf
ID: 24132479
I like the ability to upload multiple files, that helps.

Do you have any routines for inserting the image paths into the DB?

NG,

0
 
LVL 1

Accepted Solution

by:
PHPeZ earned 250 total points
ID: 24135452
Hi,

Usually, its better to store images on a folder, and just the image names on the database. I hope you're already aware of that. I'd give you an algorithm sort of thing here, you could write a routine yourself after this.

1. Have a folder created on the server (where your site is hosted).
2. Give 777 level access to that folder (remember not to use that folder for having files other than the uploaded ones there for security reasons)
3. On your action script, use check to see if there's a file attached before actually moving.
eg. if(is_uploaded_file($_FILES['<yourfilefieldname>']['tmp_name']))
       {     move_uploaded_file($_FILES['<yourfilefieldname>']['tmp_name'],'<theFolderpathRelativeToThisFile>'.$_FILES['<yourfilefieldname>']['name']);
            mysql_query("INSERT INTO `filesTable` SET `fileName`='".$_FILES['<yourfilefieldname>']['name']."', `userId`='".$_SESSION['<LoggedINUserId>']."'") or die("error: ".mysql_error());
       }

This should help.
Cheers!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now