Share on Google+Share on Google+

PHP function uploaded_file() and example

Advertisement
In this part of the tutorial we will learn about the function uploaded_file() in context of file handling.And also we will see the example related to the uploaded_file() function.

Syntax for PHP uploaded_file() Function
bool
move_uploaded_file (file_name,destination)

  • move_uploaded_file() is used to move the uploaded file to other place.
  • It returns 1 if operation succeeds, none if operation fails.
  • It works only to the files uploaded by HTTP POST


PHP uploaded_file() Function with Example

Code for PHP uploaded_file() Function
<
html>
<
body>
<
form enctype="multipart/form-data" action="myupload1.php" method="POST">
<
input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Upload the file: <input name="up_file" type="file" /><br />
<
input type="submit" value="Upload It" />
</
form>
</
body>
</
html>

<?php

    $target1
= "myupload/";
    $target1
= $target1.basename($_FILES['up_file']['name']);
    if
(move_uploaded_file($_FILES['up_file']['tmp_name'], $target1)) {
       echo basename( $_FILES['up_file']['name'])." is now uploaded";
    } 
    else{
       echo "Problenm in uploading";
    }
?>

Output
swing-training.txt is now uploaded

Advertisements

Advertisement

Posted on: October 30, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.