Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to setup to upload files to the website by using PHP and MySQL

Status
Not open for further replies.

newlearner2005

Programmer
May 9, 2005
32
US
Hello everybody,

I have hard hard time to upload a file to the webpage, viewing and store it in MySQL database.
I am using apache, PHP and MySQL
I found the code on-line and tried to practice but it did not work. They said I need two files
Here is the first file "upload.html"

<html>
<head>
<title>file upload form</title>
</head>

<body>
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000"/>
Choose a file to Upload: <input name="uploadedfile" type="file"/><br/>
<input type="submit" value ="Upload File"/>
</form>

</body>
</html>

Here is the second file "uploader.php"

<?php

// Where the file is going to be placed
$target_path = "uploads/";

// Add the original file name to our target path. Result is
// "uploads/filename.extension"
$target_path = $target_path.basename($_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmpname'], $target_path))
{
echo "The file ".basename($_FILES['uploadedfile']['name']). " has been uploaded";
}
else
{
//echo "There was an error uploading the file, please try again!";
echo "There was an error uploading the file. What the hell ! I am so disappointed!";
}

?>
Why it did not work ?
"basename" is a key word or I have to replace it ?
$target_path = "uploads/"; "uploads/" is a keyword too?

Could anybody help me ? I really appreciate.
Thank you so very much.
new learner
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top