473,503 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to upload pictures and relate them to specific users

Please help me understand the big picture of allowing users to upload
pictures and keep them separate and tied to their record in the database.

I want the whole thing automated and I'm just trying to get my arms around
what all is entailed.

Each user will upload about 20 - 100 pictures and each will be related to a
different database record.

I see the process in general as this:
- when the user registers, a picture directory should be automatically
created
- user creates a record in the database using a form AND uploads a picture
for that record (how is that picture marked as related to that record?)

I'd appreciate any big picture advice AND links to code for any part of this
process.

Any security concerns? How do I handle those?

Many thanks!
Jul 17 '05 #1
2 2640
"NotGiven" <no****@nonegiven.net> wrote in message news:<bb*****************@bignews6.bellsouth.net>. ..
Please help me understand the big picture of allowing users to upload
pictures and keep them separate and tied to their record in the database.

I want the whole thing automated and I'm just trying to get my arms around
what all is entailed.

Each user will upload about 20 - 100 pictures and each will be related to a
different database record.

I see the process in general as this:
- when the user registers, a picture directory should be automatically
created
mkdir($username)
- user creates a record in the database using a form AND uploads a picture
for that record (how is that picture marked as related to that record?)
relate the picture however you like. you could for instance store the
path/filename in your db-record or - if you have a primary key - just
rename the picture to $primary_key.jpg.

best way in my opinion, cause it saves you having writeable
directories in your site, store the pictures in the db as well (look
at BLOB-fields).

let's suppose we uploaded the picture from a form field called 'image'
(uses mysql):

$image_string = addslashes(file_get_contents($_FILES['image']['tmp_name']));
//convert image into a string, addslashes() to mask special chars that
mess up the query

$type = exif_imagetype($_FILES['bild']['tmp_name']);
//find out the image type (i.e. jpg)

$query = mysql_query("INSERT INTO table SET type = '$typ', image =
'$image_string'");

now the db contains the image as a string. to get it out and display
it:

$ih = imagecreatefromstring($image_string);

switch ($type)
{
case 1: //gif
header("Content-type: image/gif");
imagegif($ih);
break;
case 2: //jpeg
header("Content-type: image/jpeg");
imagejpeg($ih);
break;
case 3: //png
header("Content-type: image/png");
imagepng($ih);
break;
}
this little script can be used in html-img-tags just like an image(img
src="this_script.php")
I'd appreciate any big picture advice AND links to code for any part of this
process.

Any security concerns? How do I handle those?
well, directorys where people can just automatically upload files

Many thanks!

Jul 17 '05 #2
thansk!

"chotiwallah" <ch*********@web.de> wrote in message
news:78*************************@posting.google.co m...
"NotGiven" <no****@nonegiven.net> wrote in message news:<bb*****************@bignews6.bellsouth.net>. ..
Please help me understand the big picture of allowing users to upload
pictures and keep them separate and tied to their record in the database.
I want the whole thing automated and I'm just trying to get my arms around what all is entailed.

Each user will upload about 20 - 100 pictures and each will be related to a different database record.

I see the process in general as this:
- when the user registers, a picture directory should be automatically
created


mkdir($username)
- user creates a record in the database using a form AND uploads a picture for that record (how is that picture marked as related to that record?)


relate the picture however you like. you could for instance store the
path/filename in your db-record or - if you have a primary key - just
rename the picture to $primary_key.jpg.

best way in my opinion, cause it saves you having writeable
directories in your site, store the pictures in the db as well (look
at BLOB-fields).

let's suppose we uploaded the picture from a form field called 'image'
(uses mysql):

$image_string =

addslashes(file_get_contents($_FILES['image']['tmp_name'])); //convert image into a string, addslashes() to mask special chars that
mess up the query

$type = exif_imagetype($_FILES['bild']['tmp_name']);
//find out the image type (i.e. jpg)

$query = mysql_query("INSERT INTO table SET type = '$typ', image =
'$image_string'");

now the db contains the image as a string. to get it out and display
it:

$ih = imagecreatefromstring($image_string);

switch ($type)
{
case 1: //gif
header("Content-type: image/gif");
imagegif($ih);
break;
case 2: //jpeg
header("Content-type: image/jpeg");
imagejpeg($ih);
break;
case 3: //png
header("Content-type: image/png");
imagepng($ih);
break;
}
this little script can be used in html-img-tags just like an image(img
src="this_script.php")
I'd appreciate any big picture advice AND links to code for any part of this process.

Any security concerns? How do I handle those?


well, directorys where people can just automatically upload files

Many thanks!

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2900
by: Tihon | last post by:
Hello! I again need your help, just can't understand whats going on. Got this upload pictures form and it's having problem handling large files (~1.5 - 2 MB). Everything works fine if i just...
2
1892
by: Ken | last post by:
I am trying to upload a file to an Apache2 server on Windows 2000 Pro. The temp file name is being added to the database. Everything seems to work except the file is not actually transferred to...
1
3714
by: Dean | last post by:
First I've must say Im completly new in php scripting What I need to do is upload, resize pictures with path in database Here is theory of it, and plan of doing it Hope somebody can help me...
9
5391
by: Don | last post by:
How do I retrieve the full path (C:\.....filename) of a file uploaded to a php script on the server. I think $_FILES will only provide 'name', which is only the filename itself. Thanks, Don ...
3
1976
by: Kitt Langkilde | last post by:
Please Help. I run my applications perfectly, can make changes to my database, but I cannot upload Documents or Pictures Etc. Etc. Can anyone help me. I was able to with my Windows ME OS. I...
7
350
by: Shelly | last post by:
I do what most programmers do -- we steal code from stuff we have written before, or accept code from others that works, before we attempt to write something altogether new. On a previous...
4
5468
by: kev | last post by:
Hi folks, I have created a database to store information on equipments. During the first level of registration, there is a form that i need the user to fill up details on the equipment testing....
21
34323
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
7
3719
by: dragiton | last post by:
SA Upload SQL Database variable types (image upload and storage) I am having trouble with the SA Upload utility. The following code used to work correctly. However, I lost my database and had to...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.