0
Welcome Guest! Login
0 items Join Now

Component to let visitors upload files to my server

    • Franck's Avatar
    • Franck
    • Elite Rocketeer
    • Posts: 1049
    • Thanks: 0

    Component to let visitors upload files to my server

    Posted 17 years 3 months ago
    • Hello,

      I'm searching for a simple solution to let visitors upload .txt, .doc or pdf files in my server; I don't want to restrict this function to registered users. I need a simple system for upload. Someone know something I can implement?

      Thx
  • Re: Component to let visitors upload files to my server

    Posted 17 years 3 months ago
    • There's probably some custom component now, but this is what I did a couple of years ago -

      create a file called uploader.html -
      <html>
       
       <head>
      &nbsp; <title>File Uploader</title>
       </head>
       
       <body>
      &nbsp; <h3>File Upload</h3>
      &nbsp; Select file to upload:<br>
       
      &nbsp; <form action="uploader.php" method="post" enctype="multipart/form-data">
      &nbsp; <input type="file" name="file" size="45">
      &nbsp; <br>
      &nbsp; <input type="submit" value="Upload File">
      &nbsp; </form>
       
       </body>
       
      </html>

      Create a menu button (wrapper) to link to the above file.

      Then create another file called uploader.php -
      <?php
       
           if( $_FILES['file']['name'] != "" )
           {
           &nbsp; copy ( $_FILES['file']['tmp_name'],
                 "" . $_FILES['file']['name'] )
           &nbsp; or die( "Could not copy file" );
           }
           else
           {
           &nbsp; die( "No file specified" );
           }
       
      ?>
       
      <html>
       
       <head>
      &nbsp; <title>Upload complete</title>
       </head>
       
       <body>
       
      &nbsp; <h3>File upload succeeded...</h3>
      &nbsp; <ul>
      &nbsp; <li>Sent: <?php echo $_FILES['file']['name']; ?></li>
      &nbsp; <li>Size: <?php echo $_FILES['file']['size']; ?> bytes</li>
      &nbsp; <li>Type: <?php echo $_FILES['file']['type']; ?></li>
      &nbsp; </ul>
       
      &nbsp; <a href="<?php echo $_FILES['file']['name']; ?>">Click here to view file</a>
       
       </body>
       
      </html>


      Mine is restricted to specific people and seems to work OK.
      I'm not sure I would want to make it available for public access ;)
    • Franck's Avatar
    • Franck
    • Elite Rocketeer
    • Posts: 1049
    • Thanks: 0

    Re: Component to let visitors upload files to my server

    Posted 17 years 3 months ago
    • Yes I know what you mean about public access but it's for this reason I want to restrict files to .txt, .doc and pdf... Do you know if it's possible with your script. Also, where I define the path where file will be uploaded?

      Thx in advance ;)
  • Re: Component to let visitors upload files to my server

    Posted 17 years 3 months ago
    • The file would be uploaded to the same directory as the scripts.
      So you could just make your /upload directory (or whatever), put the scripts in it and set the menu button to link to the correct path.

      You could validate the file extension in the PHP script.

Time to create page: 0.069 seconds