SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: $_FILES Problem

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_FILES Problem

    Hi

    I'm having a problem with $_FILES, I have a form which refreshs its self display all the data which was entered by the user, the user may unload one picture for there profile on submit click the picture uploads fine and is stored into a folder the problem I have is that if the user presses the f5 the fresh button the picture is added again to the folder, what i would like to know is there a way of stopping this, I have been working with some code and nothing seems to work
    Code PHP:
     
    if(isset($_FILES['file']))
    {
     
    move_uploaded_file($_FILES["file"]["tmp_name"],$url  .      $_SESSION['server_side']['sexdropbox'] . "-"
    . time() . "-" . $_FILES["file"]["name"]);
    unset($_FILES);
     
    }

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    when someone hits refresh, the script is run again.

    So the best thing to do is have the upload script in one file, and redirect with the other.

    So:

    1. The form submits to upload.php
    2. upload.php uploads the file, then redirects to viewUpload.php. It sends information e.g. the filename etc through either a session or $_GET
    3. viewUpload.php simply views the uploaded file information. Upon refreshing, it simply just loads the viewing part without sending any form information
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jake Arkinstall View Post
    when someone hits refresh, the script is run again.

    So the best thing to do is have the upload script in one file, and redirect with the other.

    So:

    1. The form submits to upload.php
    2. upload.php uploads the file, then redirects to viewUpload.php. It sends information e.g. the filename etc through either a session or $_GET
    3. viewUpload.php simply views the uploaded file information. Upon refreshing, it simply just loads the viewing part without sending any form information

    Thanks i was thinking of something on those lines, out of interest can i do something with AJAX to solve this problem, has i have just got my first AJAX script working today.

    Thanks

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What you mean? Do you mean you worked successfully to upload the file via AJAX? It is not easy to upload the files with AJAX. So better and safe way to upload the files would be to use the page reloading and do what Jake has already suggested. If you don't want to create multiple pages then you can even manage everything in a single file too:

    Suppose your file is upload.php:
    PHP Code:
    <?hp
    if($_SERVER['REQUEST_METHOD'] == 'POST'){
        
    // do upload the file
        // redirect the same page upload.php
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
        <meta name="author" content="Raju Gautam" />

        <title>Untitled 1</title>
    </head>
    <body>
    <form method="post" action="upload.php" name="frm1">
        // your form goes here....
    </form>
    </body>
    </html>
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •