index.html
- <html>
- <body>
- <form action="uploader.php" 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>
uploader.php
- <?php
- if($_FILES['userfile']['type'] != "p_w_picpath/gif") {
- echo "Sorry, we only allow uploading GIF p_w_picpaths";
- exit;
- }
- // Where the file is going to be placed
- $target_path = 'uploaded_files/';
- /* Add the original filename to our target path.
- Result is "uploaded_files/filename.extension" */
- $target_path = $target_path . basename( $_FILES['file']['name']);
- if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
- echo "The file ". basename( $_FILES['file']['name']).
- " has been uploaded";
- } else{
- echo "There was an error uploading the file, please try again!";
- }
- ?>