11 Replies Latest reply on Nov 18, 2007 2:04 AM by eokorie

    Image upload / resize in "Update Record" form?

      Hi

      I've created a form to add products to a database, it includes an image field using the "upload and resize image" behavior. This works fine.

      But now I'm building the uèpdate form and want to offer users the possibility of either retaining the current file, uploading a new image to the server (and delete/overwrite the previous one if it exists) or delete the current image without uploading a new one.

      how would i go about this?

      thanks.
        • 1. Re: Image upload / resize in "Update Record" form?
          Waleed Barakat Level 1
          hi,

          I just made a pre InterAKT tutorial.

          and found it useful for managing sites that relying on products and shopping carts that allow site admin to manage all his store products that have images attached with.

          To view this online tutorial please click on the link below and follow:
          ======================================================================
          http://www.amp-eg.com/Delete_image
          -----------------------------------
          • 2. Re: Image upload / resize in "Update Record" form?
            Hi I am having the same issues as somaboy and I went through your tutorial but didnt see any thing using the update wizard,
            I have a field with the path to an image. it is called the news table and people can upload an image along with the news, the add news portion with the image uploading to the image directory works fine, but when using the update wizard, I do not see the image when going to update, and all I have is a browse button to select an image before updating, I want to be able to change the image on the update page and cant seem to do this. in other words, when changing pic on update page, it should delete the existing image from the server and upload the new image and also place it in the database.
            ANY HELP would be greatly appreciated.
            Thank You
            Dave
            • 3. Re: Image upload / resize in "Update Record" form?
              Waleed Barakat Level 1
              hi, Dave
              how are you?
              thanks for walking through the tutorial,

              but i think you have to re navigate this part and read it carefully, why i told you that because in this part particularly you can learn how to show images in NeXTensio lists "show thumbnail" sb.

              in this part:
              -------------
              http://www.amp-eg.com/Delete_image/part3.htm

              and i f you read the tutorial from the beginning you can see that it separated into 1-2-3-4-5-6 steps it looks like this:
              ------------------------------------------------------
              3- On product update, if a new image is selected, replace the old one both on the disk and in the database.
              4- On product update, if a Delete image checkbox is selected, the image must be removed from the disk and from the database.
              5- When a record is deleted, its image must be removed as well.

              this steps will solve your problem when updating record associated with images.

              please read it again and i am all ears if there is any problems.

              thank you very much
              waleed barakat
              • 4. Re: Image upload / resize in "Update Record" form?
                Günter Schenk Level 4
                Hi Waleed,

                the procedure of removing files that´s described in the tutorial refers to situations when a record is deleted -- Somaboy´s and Daves requirement is a little more complicated, because they want this to happen when updating a record.

                As far as I see it, this would only be possible by implementing a custom "before" trigger, and that´s something someone would have you write a tutorial about :-)

                Unless someone finds out how to implement such a custom trigger, it´s still quite easy to replace the current image with another one, without deleting it from the server -- however, I´m attaching a text-only PHP snippet which will at least display the currently stored image on the update form -- it´s using PHP´s getimagesize() function and will "on the fly" scale the original image to 1/2 of it´s size.

                You´ll see that this example uses an ADDT Show IF Conditional Region behaviour in order to only display that image *if* the DB´s image column isn´t empty

                Cheers,
                Günter Schenk
                Adobe Community Expert, Dreamweaver
                • 5. Re: Image upload / resize in "Update Record" form?
                  Waleed Barakat Level 1
                  Hi Gunter,
                  i bit sure you`re right but i read the tutorial again and forund there is a already custom_trigger that do replace the current image if i choose that and not check the "delete image" checkbox if so this custom_trigger will executed: *AFTER*
                  ------
                  $query = "UPDATE product_prd SET image_prd = '' WHERE id_prd = ".$tNG->getPrimaryKeyValue();
                  $tNG->connection->execute($query);
                  return NULL;
                  ------
                  - so if i clicked the *browse* button to select a new image it will be replaced by the existing one.

                  - and if i update only the text *text area" text and checked the *delete image* checkbox the record will be updated and the image will be deleted fro the server.

                  am i wrong?
                  i think i have to made an live example for that...
                  • 6. Re: Image upload / resize in "Update Record" form?
                    Günter Schenk Level 4
                    Hi Waleed,

                    oops, yes, sorry, you´re right of course -- just didn´t read it too carefully :-)

                    However, what Somaboy and Dave want, is a little different from what the tutorial explains at this point -- what´s explained there, will of course be deleting that image physically and erasing the file name entry from the table, but that won´t cover the requirement to additionally upload another picture from the same form.

                    In this special case I *think* that one would have to perform both deletion processes as "before" triggers -- to make sure that the file as such plus the corresponding table entry are really gone before the upload procedure happens.

                    If someone will ever find out a well-working strategy to get this (BTW very often asked for) requirement done, many folks here would certainly jump for joy -- also because that´s something you apparently can´t do without implementing a chain of at least custom triggers.

                    But there´s also a much easier solution available to those folks who don´t want to bother with implementing custom triggers for this purpose alone :: this is how I´d do it:

                    1. use what´s described in step 3 of the tutorial you posted to delete the physical file and the "filename" column entry

                    2. pass the current recordset´s ID to the "redirect after update" page, and here...

                    3. add a "SELECT file_column FROM table_name WHERE ID" matches the URL parameter ID - query in order to check if this column is empty or not -- and if it´s empty, execute an "upload and resize image" behavior on this page.

                    Cheers,
                    Günter Schenk
                    Adobe Community Expert, Dreamweaver
                    • 7. Re: Image upload / resize in "Update Record" form?
                      Waleed Barakat Level 1
                      Hi Gunter,
                      always brilliant, yes this is the best way to implement that task in the few steps you described instead of complicated custom triggers.

                      thanks and i hope that help Dave and somaboy as it helped me too.
                      • 8. Re: Image upload / resize in "Update Record" form?
                        Level 1
                        Thank You so much people!! if anyone has any good tutorials on how to get this working, that would be soooo cool! I will try Gunter's above suggestion, hope I dont get lost! hahahha
                        Thanks alot
                        Dave
                        • 9. Re: Image upload / resize in "Update Record" form?
                          eokorie Level 1
                          I don't know if this will help, but i am currently working on a small project and the client has requested something similar. I have actually used a combination of Spry and ADDT for this. You can see an example here.

                          http://www.grafikkaos.co.uk/gk-tutorials/image-upload/books.php

                          You can add a new record or manage the current one. On the update form, when an image has been uploaded, I added a delete link right under the image, and using spry, I call on the delete_image.php file, to update the details of that record and to physically detele file from the server. Once that is done, the user is then brought back to the update form when he can choose to upload a new image. Don't know if i am explaining this right. If you want the files, let me know...
                          • 10. Re: Image upload / resize in "Update Record" form?
                            Waleed Barakat Level 1
                            there is nothing of what you described here are working, i tried what you said and there is nothing,

                            the image still in there even if i clicked the delete link and one other note:
                            ------------
                            you are using *dynamic forms* without using Dynamic NEXtensio lists so if you clicked the *edit* link it will redirect you to the update page but try to click *cancel* button it will go no where.

                            i am only try to say my comments...

                            thanks
                            • 11. Re: Image upload / resize in "Update Record" form?
                              eokorie Level 1
                              Yes Waleed i know i am using dynamic nextensio lists without using the dynamic forms. It was deliberate seeing as this was a quick rough example!?????? And besides, you don't necessarily have to use NexTensio lists and dynamic forms every time. As for the Cancel button, since it matters that much to you, I have linked it back to the books.php page (hope that makes you very happy.)

                              by the way, i have corrected the error in my code. I did not upload the update delete_image.php file. This has now been corrected.

                              Looking forward to an example from you Waleed!