Helping ordinary people create extraordinary websites!

How to Upload Files with PHP

By Darren W. Hedlund
2005-06-21

How to Upload Files with PHP

This tutorial will cover how to make a basic PHP upload script. You can easily convert or change it.

You need a PHP enabled host, the ability to upload, and HTML or PHP knowledge to change the script around to fit your needs

This is the basic code:


<form enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="2048000">
File: <input name="userfile" type="file" /><br />
<input type="submit" value="Upload" />
</form>

<?php
if (@is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
copy($_FILES["userfile"]["tmp_name"], "$/images/" . $_FILES["userfile"]["name"]);
echo "<p>File uploaded successfully.</p>";
}
?>


You can change the "/images/" to any directory you want.

You may also want to password protect the file. This is so only webmasters or selected people can view it.




Tutorial pages:
  • How to Upload Files with PHP

 1 Votes

You might also want to check these out:


Leave a Comment on "How to Upload Files with PHP"
You must be logged in to post a comment.

Link to This Tutorial Page!


GET OUR NEWSLETTERS