Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question File editing and uploading?

    Hi guys,

    I'm very unsure on how to go about achieving this.
    I'd like to have a page where a user is able to:
    1. Upload a file (.doc file, .txt file, images) and preferrably store these files somewhere in a sub-folder (all are done through a web interface, not ftp).
    2. Post texts - Just one big piece of text, and the ability to edit it themself. So its like one big textbox.

    I'm open to any solutions.

    Thank you in advance for any help. =).

  • #2
    Regular Coder
    Join Date
    Mar 2004
    Location
    Australia
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post
    Ok so if i understand you correctly you are after a form that a user can browse their files and then upload one with the correct file extension?

    ok well i have recently built a site for a customer that required them to keep the stocklist up to date, so i put this together. If you see anything wrong with it then please let me know.

    1. Create a form like the following

    Code:
    <form action="upload.php" method="post" ENCTYPE="multipart/form-data">
      File:
      <input type="file" name="file2" size="30">
      <input name="submit2" type="submit" value="Update">
    </form>



    2. Create a php page called upload.php or similar and add the following code

    PHP Code:
    <?php
    // ==============
    // Configuration
    // ==============
    $uploaddir "files"// Where you want the files to upload to - Important: Make sure this folders permissions is 0777!
    $allowed_ext "doc, txt, xls"// These are the allowed extensions of the files that are uploaded
    $max_size "50000"// 50000 is the same as 50kb - depends on what you are uploading
    $max_height ""// This is in pixels - Leave this field empty if you don't want to upload images
    $max_width ""// This is in pixels - Leave this field empty if you don't want to upload images 

    // Check Entension
    $extension pathinfo($_FILES['file']['name']);
    $extension $extension[extension];
    $allowed_paths explode(", "$allowed_ext);
    for(
    $i 0$i count($allowed_paths); $i++) {
     if (
    $allowed_paths[$i] == "$extension") {
     
    $ok "1";
     }
    }

    // Check File Size
    if ($ok == "1") {
    if(
    $_FILES['file']['size'] > $max_size)
    {
    header("Location: http://www.yoursite.com.au/?page=error_upload");
    }

    // Check Height & Width
    if ($max_width && $max_height) {
    list(
    $width$height$type$w) = getimagesize($_FILES['file']['tmp_name']);
    if(
    $width $max_width || $height $max_height)
    {
    header("Location: Location: http://www.yoursite.com.au/?page=error_upload");
    }
    }

    // The Upload Part
    if(is_uploaded_file($_FILES['file']['tmp_name']))
    {
    move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
    }
    header("Location: http://www.yoursite.com.au/?page=upload_success");
    } else {
    header("Location: http://www.yoursite.com.au/?page=error_upload");
    }
    ?>
    3. You can now create the error and success pages to let them know of it worked or not.

    4. from experiences so far it overwrites the older file. If people think different then please tell me.

    5. Please note that you should ensure that this is fairly secure (login before hand or soemthing) and i wouldnt allow upload of exe files ect

    enjoy


  •  

    Posting Permissions

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