www.webdeveloper.com
Results 1 to 6 of 6

Thread: [RESOLVED] File Upload or Delete with Database Entries?

  1. #1
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    265

    resolved [RESOLVED] File Upload or Delete with Database Entries?

    Ok, so here's what I've got (more or less) for the file-upload form:
    HTML Code:
    <tr>
        	<td><input type="text" name="title_new" /></td>
        	<td colspan="2"><input name="file_new" type="file" class="file" /></td>
        	<td><select name="category_new">
            	<option value="1">Category 1</option>
            	<option value="2">Category 2</option>
            	<option value="3">Category 3</option>
            </select></td>
        	<td class="boxed"><input type="checkbox" name="show_new" value="1" /></td>
        	<td class="boxed"><input type="checkbox" name="delete_new" value="please" onClick="return confirm('Are you sure you want to cancel this file upload?')" /></td>
    </tr>
    That's for the "add new" area... There is also a "delete" checkbox for the list of existing files... pretty much the same as the "cancel" checkbox here.

    I cannot seem to get a file-uploader to work... at all.

    The target-directory is called "docs" and that folder is sitting in the same directory as this page (so it's just "docs/" from where I'm at)

    I need it to check if filenames already exist and add something to the end of it so the filename is unique...

    and I need it to delete files from the server if the delete button is selected for it. I can isolate the one that needs to be removed, I just don't know how to remove it.

    Any help would be greatly appreciated... Feel free to ask questions if you need more clarification. I'm sure my request is as clear as mud.

  2. #2
    Join Date
    Jan 2009
    Posts
    3,346
    Where is the code handling the upload? All I see is a form to allow a user to submit a file, but nothing that handles the copying of the file from the temporary space to the desired directory.

  3. #3
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    265
    That's exactly the problem I'm having... The file-upload part of the form processor doesn't work. I have tried 10 different tutorials but I keep royally screwing it up every time I try to put something together that works. I just don't understand PHP file uploads.

  4. #4
    Join Date
    Jan 2009
    Posts
    3,346
    How about you post the php code you are having trouble with along with any errors you may be encountering so we can see if there is some assistance we could provide?

  5. #5
    Join Date
    Mar 2012
    Posts
    63
    <?php
    if(isset($_REQUEST['submit'])) {

    if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/pjpeg"))
    && ($_FILES["file"]["size"] < 20000))
    {
    if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
    else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
    {
    echo $_FILES["file"]["name"] . " already exists. ";
    }
    else
    {
    move_uploaded_file($_FILES["file"]["tmp_name"],
    "upload/" . $_FILES["file"]["name"]);
    echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
    }
    }
    }
    else
    {
    echo "Invalid file";
    }
    }
    ?>

    <html>
    <body>

    <form action="" method="post" enctype="multipart/form-data">
    <label for="file">Filename:</label>
    <input type="file" name="file" id="file" />
    <br />
    <input type="submit" name="submit" value="Submit" />
    </form>

    </body>
    </html>

  6. #6
    Join Date
    Nov 2011
    Location
    Nigeria
    Posts
    28
    i guess that code is from w3schools. com
    If you check their file upload form,
    the name of their file input is file
    HTML Code:
    <input type="file" name="file" />
    that is why they used "file"
    in their $_FILES array.
    LIKE:
    Code:
    $_FILES['file']
    In this case, the name of your file upload input is file_new
    HTML Code:
    <input type="file" name="file_new"/>
    So your code should be something like
    Code:
    $_FILES['file_new']['size']
    
    $_FILES['file_new']['type'] . . .
    etc
    hope it helps
    Last edited by ibixxon; 05-04-2012 at 03:45 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles