No announcement yet.

Image (database) question

  • Filter
  • Time
  • Show
Clear All
new posts

  • Image (database) question

    My version: 8.1.006
    So I have an image (database) field on my form with 3 extensions to allow. Pretty cool, I thought, until a user reported this problem (and I confirmed).

    The user is allowed to upload an image with an extension different from those in the allow list. When the form I saved, the validation catches the wrong extension. However, there is no way for the user to remove the wrong image. They are stuck. All work they did on the form can not be saved because of the image validation rule (really because SC allow an illegal image to be uploaded in the first place).

    It seems to me, SC should only permit images with the permitted extensions to be uploaded.

    Does anyone know how I can check the uploaded image's extension so I can delete it so the user can save the form?

  • #2
    I think it would be much better to allow the user to select only valid extensions.
    Here it is.

    If you did not already, enable the footer for the form.
    Add a global variable of type Value to the footer. [valid_ext]
    Place the following code to the onApplicationInit event.

    [valid_ext] = "<script>$('#id_sc_field_xxx').attr('accept','.gif , .png');</script>"; //replace 'xxx' with the name of your image field and change the extensions to fit your needs

    Note: This is for the 'Browse' button only, so I suggest you remove the 'Drop zone'.



    • #3
      I appreciate your solution, I see your approach inserts a script at the bottom of the source page.

      I feel stupid having to ask this question. How do I add the global to the footer?

      When the footer contains the text "[valid_ext]" is displayed in the footer.
      When the footer contains the text "<?php echo [valid_ext]; ?>", the word 'Array' is displayed in the footer.



      • #4
        Don't you hate it when you hit the Post button, and then figure out the answer...

        I found this works:
        <?php echo $_SESSION['valid_ext']; ?>



        • #5
          Your tip helped. Thanks

          I also discovered:
          1. some images (jpg) would upload fine that had a dash in them, others would not. I thought there must be some issue in the jpg, but when I removed the dash from the file name, the jpg uploaded OK.

          I will be looking for a more robust image upload solution, if anyone has any suggestions.

          Hope this saves someone else time.


          • #6
            I feel stupid having to ask this question. How do I add the global to the footer?
            Layout -> Header & Footer -> Footer

            Display Footer: Yes
            Select one of the Footer Variables.
            Select Value.

            Put [valid_ext] in the input field.

            It's a known problem in SC with special characters in file names which isn't fixed yet.
            Search the forum, there are some suggestions for an individual solution.