Solved

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

Posted on 2009-04-09
10
474 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When deciding to adopt any help desk solutions many factors should be explored before taking decisions. This will change from business to another but in general there are some kind of rule of thumb. Here are some quick tips: Do we need only ticket…
This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. 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 :…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

687 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