Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

upload file -quick question

  • 09-08-2010 7:42pm
    #1
    Registered Users, Registered Users 2 Posts: 1,180 ✭✭✭


    hey guys, i have a script which allows a user to upload an image. however if the image is over 2mb or not a specific file type, then an error is printed and they must re-upload a smaller image
    however if the user goes back to the image upload page, the old image path is in the box and i can't delete it (by using backspace or delete button or anything!)

    is there a way to fix this? without having to redirect to a fresh upload page?

    here is a small bit of the code:
    <form enctype="multipart/form-data" action="upload.php" method="post">
          <input type="file" name="image" id="image" />
    </form>
    


Comments

  • Registered Users, Registered Users 2 Posts: 6,571 ✭✭✭daymobrew


    Maybe try setting the value. I have not tested this.
    <form enctype="multipart/form-data" action="upload.php" method="post">
          <input type="file" name="image" id="image"  [B]value=""[/B] />
    </form>
    


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    You could try a header redirect to the original page on error, e.g.
    <?php if ($filesize_error) {
        header("Location:uploadPage.php?reason=filesize");
        die();
    }
    ?>
    

    Then, on the upload page
    <?php if ($_GET["reason"]=="filesize") { ?>
    <pThe image file that you uploaded was not a valid filesize</p> 
    <?php } ?>
    <form enctype="multipart/form-data" action="upload.php" method="post">
          <input type="file" name="image" id="image" />
    </form>
    


  • Registered Users, Registered Users 2 Posts: 1,180 ✭✭✭EyeSight


    Liam Byrne wrote: »
    You could try a header redirect to the original page on error, e.g.
    <?php if ($filesize_error) {
        header("Location:uploadPage.php?reason=filesize");
        die();
    }
    ?>
    
    Then, on the upload page
    <?php if ($_GET["reason"]=="filesize") { ?>
    <pThe image file that you uploaded was not a valid filesize</p> 
    <?php } ?>
    <form enctype="multipart/form-data" action="upload.php" method="post">
          <input type="file" name="image" id="image" />
    </form>
    
    thanks for the reply. i think i understand what you're saying, except for this
    if ($_GET["reason"]=="filesize")
    
    am i right by assuming on redirect, it sends the reason via GET and then on the page where the images can be uploaded, it reads the GET array?

    also the
    value=""
    
    doesn't work :( thanks anyway


  • Closed Accounts Posts: 24 zoudards


    I don't think you can write in the input field of type "file", you can only chose the file by clicking the relevant button. Most of the browsers will remember what the form fields' values were set to if you click back on your browser, i'm afraid you have to either add a client side script that reset the field on load or refresh the page. depending how big the page is, a refresh is a lot simpler.


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    EyeSight wrote: »
    am i right by assuming on redirect, it sends the reason via GET and then on the page where the images can be uploaded, it reads the GET array?

    Yup!

    Basically you're not showing the upload target page if the file is too big (you're redirecting back to the original page), so you're sending a variable back to say "show the paragraph on that page that relates to the 'resize' error".

    If there's no $_GET["reason"] variable, then that paragraph doesn't appear, which caters for when they visit the page at first.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 241 ✭✭fcrossen


    I've also used something like:

    [HTML]<input type="file" name="image<?php echo str_replace( array(' ','.') , '' , microtime() ); ?>" id="image" />[/HTML]

    to prevent browser autocomplete on fields like usernames.

    This will append a unique string to your name field:

    [HTML]<input type="file" name="image0457457001281600026" id="image" />[/HTML]

    Instead of looking for a POST var called "image" you look for one that starts with "image".


Advertisement