how to upload pictures and relate them to specific users

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NotGiven

    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!


  • chotiwallah

    #2
    Re: how to upload pictures and relate them to specific users

    "NotGiven" <noname@nonegiv en.net> wrote in message news:<bbmUc.336 8$rd5.1235@bign ews6.bellsouth. net>...[color=blue]
    > 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[/color]

    mkdir($username )
    [color=blue]
    > - 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?)[/color]

    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.jp g.

    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("IN SERT 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 = imagecreatefrom string($image_s tring);

    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_scrip t.php")
    [color=blue]
    > 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?[/color]

    well, directorys where people can just automatically upload files
    [color=blue]
    >
    > Many thanks![/color]

    Comment

    • NotGiven

      #3
      Re: how to upload pictures and relate them to specific users

      thansk!

      "chotiwalla h" <chotiwallah@we b.de> wrote in message
      news:782d6cb.04 08172339.3c99d4 af@posting.goog le.com...[color=blue]
      > "NotGiven" <noname@nonegiv en.net> wrote in message[/color]
      news:<bbmUc.336 8$rd5.1235@bign ews6.bellsouth. net>...[color=blue][color=green]
      > > Please help me understand the big picture of allowing users to upload
      > > pictures and keep them separate and tied to their record in the[/color][/color]
      database.[color=blue][color=green]
      > >
      > > I want the whole thing automated and I'm just trying to get my arms[/color][/color]
      around[color=blue][color=green]
      > > what all is entailed.
      > >
      > > Each user will upload about 20 - 100 pictures and each will be related[/color][/color]
      to a[color=blue][color=green]
      > > different database record.
      > >
      > > I see the process in general as this:
      > > - when the user registers, a picture directory should be automatically
      > > created[/color]
      >
      > mkdir($username )
      >[color=green]
      > > - user creates a record in the database using a form AND uploads a[/color][/color]
      picture[color=blue][color=green]
      > > for that record (how is that picture marked as related to that record?)[/color]
      >
      > 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.jp g.
      >
      > 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 =[/color]
      addslashes(file _get_contents($ _FILES['image']['tmp_name']));[color=blue]
      > //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("IN SERT 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 = imagecreatefrom string($image_s tring);
      >
      > 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_scrip t.php")
      >[color=green]
      > > I'd appreciate any big picture advice AND links to code for any part of[/color][/color]
      this[color=blue][color=green]
      > > process.
      > >
      > > Any security concerns? How do I handle those?[/color]
      >
      > well, directorys where people can just automatically upload files
      >[color=green]
      > >
      > > Many thanks![/color][/color]


      Comment

      Working...