Results 1 to 2 of 2

Thread: Submit a file from a webpage

  1. #1
    Join Date
    Jul 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Submit a file from a webpage

    I have an application that allow the user to submit a file from a webpage the same way as placing an attachment in an e-mail. How can I do it with PHP? Thanks.

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Thumbs up

    Yes you can do it using PHP

    HTML Code:
    upload.html
    
    <form enctype="multipart/form-data" action="upload.php" method="POST">
    Please choose a file: <input name="uploaded" type="file" /><br />
    <input type="submit" value="Upload" />
    </form> 
    PHP Code:
    upload.php

    <?php 
    $target 
    "files/"
    $target $target basename$_FILES['uploaded']['name']); 
    $ok=1

    //This is our size condition 
    if ($uploaded_size 350000

    echo 
    "Your file is too large.<br>"
    $ok=0


    //This is our limit file type condition 
    if ($uploaded_type =="text/php"

    echo 
    "No PHP files<br>"
    $ok=0


    //Here we check that $ok was not set to 0 by an error 
    if ($ok==0

    Echo 
    "Sorry your file was not uploaded"


    //If everything is ok we try to upload it 
    else 

    if(
    move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 

    echo 
    "The file "basename$_FILES['uploadedfile']['name']). " has been uploaded"

    else 

    echo 
    "Sorry, there was a problem uploading your file."


    ?>
    This will do your job

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
  •