Skip to main content
Inspiring
August 27, 2006
Question

Question about adapting an update form for image uploads

  • August 27, 2006
  • 19 replies
  • 1810 views
I have a form that updates a recordset in a MySQL database. Vanilla stuff,
really.

I want to add the following capabilities to the form -

1. Upload an image
2. Resize the image according to preset maxwidth/height values, and save it
with the uploaded name
3. Resize it to a thumbnail and save that with a modification of the
uploaded name
4. Add the parent image name (and all the other fields) back to the
database for that particular record number

I know how to do #1, #2, and #3 (using GD to do this), but what I am not
sure about is a) how to adapt the existing form to do this (more than just
adding an image field), and b) what order to do things in.

I think I have to add 'enctype="multipart/form-data"' to the <form> tag, is
that right? Will that affect any of the rest of the functionality of the
form?

Also, I'm thinking I need to upload the image files and process them
*before* adding the data to the database - would that be the best way?

Thanks for any suggestions....

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================



This topic is closed to new replies. Start a new post to keep the conversation going.

19 replies

Inspiring
August 27, 2006
No, I have. Really! 8)

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"JED" <jed1@nomail.co.uk> wrote in message
news:ecsp0l$sm2$1@forums.macromedia.com...
> That's not what I've heard!
>
> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
> news:ecsnbf$r0n$1@forums.macromedia.com...
>> I've been VERY good....
>>
>> --
>> Murray --- ICQ 71997575
>> Adobe Community Expert
>> (If you *MUST* email me, don't LAUGH when you do so!)
>> ==================
>> http://www.dreamweavermx-templates.com - Template Triage!
>> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
>> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
>> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
>> ==================
>>
>>
>> "carl" <carl@nospam.net> wrote in message
>> news:ecsmpe$q9c$1@forums.macromedia.com...
>>> David Powers wrote:
>>>> You need a copy of my next book, "PHP Solutions". It has a fully worked
>>>> solution for exactly that. Unfortunately, it's not due out until
>>>> November. :(
>>>
>>> Santa Claus is coming to town ... :)
>>>
>>> Carl
>>
>>
>
>


Inspiring
August 27, 2006
I've been through that page a number of times - in fact the upload markup I
will use is what is shown in example 1 - it works very well. The trick is
to sequence everything.

I believe what I will do is to have an update page that shows the database
information for the selected record, and shows the thumbnail for the image.
This page will have an update button that will update the database with any
edits you make.

Next to the displayed image, there will be a button saying "select new
image" or something. Clicking that button will take you to a new page,
allowing you to browse to and select a new image. When you submit that
page, the image will be uploaded, resized into both the page's max size, and
the thumb size, and the new image's name will be entered into the database.
You will then be redirected back to the original update page, which will
show the new image.

Does that make sense? Does it seem like a logical flow?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Joe Makowiec" <makowiec@invalid.invalid> wrote in message
news:Xns982C939ED69FmakowiecatnycapdotrE@216.104.212.96...
> On 27 Aug 2006 in macromedia.dreamweaver.appdev, Murray *ACE* wrote:
>
>> I have a form that updates a recordset in a MySQL database. Vanilla
>> stuff, really.
>>
>> I want to add the following capabilities to the form -
>>
>> 1. Upload an image
>> 2. Resize the image according to preset maxwidth/height values, and
>> save it with the uploaded name
>> 3. Resize it to a thumbnail and save that with a modification of
>> the uploaded name
>> 4. Add the parent image name (and all the other fields) back to the
>> database for that particular record number
>>
>> I know how to do #1, #2, and #3 (using GD to do this), but what I am
>> not sure about is a) how to adapt the existing form to do this (more
>> than just adding an image field), and b) what order to do things in.
>>
>> I think I have to add 'enctype="multipart/form-data"' to the <form>
>> tag, is that right? Will that affect any of the rest of the
>> functionality of the form?
>>
>> Also, I'm thinking I need to upload the image files and process them
>> *before* adding the data to the database - would that be the best
>> way?
>
> I assume you've been through this?
>
> http://www.php.net/manual/en/features.file-upload.php
>
> I'm thinking as I type, so this is going to be a bit disjointed, but:
>
> - Assign a random name to the uploaded file as a first step in the
> process. You probably also want to do a database lookup to make sure
> that the name is unique. Or assign a sequential name; in this case
> you'll have to do something like SELECT MAX(filename) FROM myDatabase
> to get the starting value. There's probably some easier way to do
> this, too. You should probably do this before insert, rather than,
> say, as a hidden field in the form unless you're positive that there
> will be no collisions.
> - Save the uploaded file per the page above
> - Insert everything, including the filename, into the database. Use
> the inserted filename as a basename, so that you will eventually have:
> -- basename.jpg <- the original uploaded file
> -- basename_r.jpg <- the resized file
> -- basename_t.jpg <- the thumbnail
> That takes care of #1. You now have the image name and location. Do
> steps 2 & 3; as you save the resized and thumbnail image, append
> something (like _r and _t as suggested above) to distinguish them from
> the original upload. Or save them to separate directories. Or both.
>
> Since you assigned a basename before step 1, #4 is taken care of.
>
> --
> Joe Makowiec
> http://makowiec.net/
> Email: http://makowiec.net/email.php


Inspiring
August 27, 2006
That's not what I've heard!

"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:ecsnbf$r0n$1@forums.macromedia.com...
> I've been VERY good....
>
> --
> Murray --- ICQ 71997575
> Adobe Community Expert
> (If you *MUST* email me, don't LAUGH when you do so!)
> ==================
> http://www.dreamweavermx-templates.com - Template Triage!
> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
> ==================
>
>
> "carl" <carl@nospam.net> wrote in message
> news:ecsmpe$q9c$1@forums.macromedia.com...
>> David Powers wrote:
>>> You need a copy of my next book, "PHP Solutions". It has a fully worked
>>> solution for exactly that. Unfortunately, it's not due out until
>>> November. :(
>>
>> Santa Claus is coming to town ... :)
>>
>> Carl
>
>


Inspiring
August 27, 2006
Joe:

Thanks! I'll study that....

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Joe Makowiec" <makowiec@invalid.invalid> wrote in message
news:Xns982C939ED69FmakowiecatnycapdotrE@216.104.212.96...
> On 27 Aug 2006 in macromedia.dreamweaver.appdev, Murray *ACE* wrote:
>
>> I have a form that updates a recordset in a MySQL database. Vanilla
>> stuff, really.
>>
>> I want to add the following capabilities to the form -
>>
>> 1. Upload an image
>> 2. Resize the image according to preset maxwidth/height values, and
>> save it with the uploaded name
>> 3. Resize it to a thumbnail and save that with a modification of
>> the uploaded name
>> 4. Add the parent image name (and all the other fields) back to the
>> database for that particular record number
>>
>> I know how to do #1, #2, and #3 (using GD to do this), but what I am
>> not sure about is a) how to adapt the existing form to do this (more
>> than just adding an image field), and b) what order to do things in.
>>
>> I think I have to add 'enctype="multipart/form-data"' to the <form>
>> tag, is that right? Will that affect any of the rest of the
>> functionality of the form?
>>
>> Also, I'm thinking I need to upload the image files and process them
>> *before* adding the data to the database - would that be the best
>> way?
>
> I assume you've been through this?
>
> http://www.php.net/manual/en/features.file-upload.php
>
> I'm thinking as I type, so this is going to be a bit disjointed, but:
>
> - Assign a random name to the uploaded file as a first step in the
> process. You probably also want to do a database lookup to make sure
> that the name is unique. Or assign a sequential name; in this case
> you'll have to do something like SELECT MAX(filename) FROM myDatabase
> to get the starting value. There's probably some easier way to do
> this, too. You should probably do this before insert, rather than,
> say, as a hidden field in the form unless you're positive that there
> will be no collisions.
> - Save the uploaded file per the page above
> - Insert everything, including the filename, into the database. Use
> the inserted filename as a basename, so that you will eventually have:
> -- basename.jpg <- the original uploaded file
> -- basename_r.jpg <- the resized file
> -- basename_t.jpg <- the thumbnail
> That takes care of #1. You now have the image name and location. Do
> steps 2 & 3; as you save the resized and thumbnail image, append
> something (like _r and _t as suggested above) to distinguish them from
> the original upload. Or save them to separate directories. Or both.
>
> Since you assigned a basename before step 1, #4 is taken care of.
>
> --
> Joe Makowiec
> http://makowiec.net/
> Email: http://makowiec.net/email.php


Inspiring
August 27, 2006
On 27 Aug 2006 in macromedia.dreamweaver.appdev, Murray *ACE* wrote:

> I have a form that updates a recordset in a MySQL database. Vanilla
> stuff, really.
>
> I want to add the following capabilities to the form -
>
> 1. Upload an image
> 2. Resize the image according to preset maxwidth/height values, and
> save it with the uploaded name
> 3. Resize it to a thumbnail and save that with a modification of
> the uploaded name
> 4. Add the parent image name (and all the other fields) back to the
> database for that particular record number
>
> I know how to do #1, #2, and #3 (using GD to do this), but what I am
> not sure about is a) how to adapt the existing form to do this (more
> than just adding an image field), and b) what order to do things in.
>
> I think I have to add 'enctype="multipart/form-data"' to the <form>
> tag, is that right? Will that affect any of the rest of the
> functionality of the form?
>
> Also, I'm thinking I need to upload the image files and process them
> *before* adding the data to the database - would that be the best
> way?

I assume you've been through this?

http://www.php.net/manual/en/features.file-upload.php

I'm thinking as I type, so this is going to be a bit disjointed, but:

- Assign a random name to the uploaded file as a first step in the
process. You probably also want to do a database lookup to make sure
that the name is unique. Or assign a sequential name; in this case
you'll have to do something like SELECT MAX(filename) FROM myDatabase
to get the starting value. There's probably some easier way to do
this, too. You should probably do this before insert, rather than,
say, as a hidden field in the form unless you're positive that there
will be no collisions.
- Save the uploaded file per the page above
- Insert everything, including the filename, into the database. Use
the inserted filename as a basename, so that you will eventually have:
-- basename.jpg <- the original uploaded file
-- basename_r.jpg <- the resized file
-- basename_t.jpg <- the thumbnail
That takes care of #1. You now have the image name and location. Do
steps 2 & 3; as you save the resized and thumbnail image, append
something (like _r and _t as suggested above) to distinguish them from
the original upload. Or save them to separate directories. Or both.

Since you assigned a basename before step 1, #4 is taken care of.

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/email.php
Inspiring
August 27, 2006
I've been VERY good....

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"carl" <carl@nospam.net> wrote in message
news:ecsmpe$q9c$1@forums.macromedia.com...
> David Powers wrote:
>> You need a copy of my next book, "PHP Solutions". It has a fully worked
>> solution for exactly that. Unfortunately, it's not due out until
>> November. :(
>
> Santa Claus is coming to town ... :)
>
> Carl


Inspiring
August 27, 2006
David Powers wrote:
> You need a copy of my next book, "PHP Solutions". It has a fully worked
> solution for exactly that. Unfortunately, it's not due out until
> November. :(

Santa Claus is coming to town ... :)

Carl
Inspiring
August 27, 2006
> You need a copy of my next book, "PHP Solutions". It has a fully worked
> solution for exactly that. Unfortunately, it's not due out until November.
> :(

Bah! 8)

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"David Powers" <david@example.com> wrote in message
news:ecsj79$mt1$1@forums.macromedia.com...
> Murray *ACE* wrote:
>> I know how to do #1, #2, and #3 (using GD to do this), but what I am not
>> sure about is a) how to adapt the existing form to do this (more than
>> just adding an image field), and b) what order to do things in.
>
> You need a copy of my next book, "PHP Solutions". It has a fully worked
> solution for exactly that. Unfortunately, it's not due out until November.
> :(
>
> --
> David Powers
> Adobe Community Expert
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> http://foundationphp.com/


Inspiring
August 27, 2006
Murray *ACE* wrote:
> I know how to do #1, #2, and #3 (using GD to do this), but what I am not
> sure about is a) how to adapt the existing form to do this (more than just
> adding an image field), and b) what order to do things in.

You need a copy of my next book, "PHP Solutions". It has a fully worked
solution for exactly that. Unfortunately, it's not due out until
November. :(

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/