Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-04-09
10
Medium Priority
?
489 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Geo-targeting is the practice of distributing content based on a person’s location, as best as you can determine it. Let’s look at some ways you could successfully use this tactic. The following tips and case studies could lead to meaningful results.
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. 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 : Open Page or Post…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
Suggested Courses

597 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