How to make a PHP uploader script?
Ive tried so many times to make them but they never work.
I want one that can allow people to upload there pictures to my site and the name of the file changes to whatever their username is. Also so the file gets sent to the file on my host called "pictures". I nearly cracked it then got stuck again lol.
Anyone know how?
(ive check and my host does allow this so thts good)
September 6, 2010 | Filed Under Scripts FAQs
Comments
2 Responses to “How to make a PHP uploader script?”
Powered by Yahoo! Answers
Drop this code into a php web page:
<?php
if (isset($_POST['submit'])){
//you will need to change the path to where you want to upload to. Below
//will place the uploaded file into the same dir as this php file.
$uploadDirFile = realpath("./") . "\\" . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['name'];
$uploadMsg = "";
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $uploadDirFile)) {
$uploadMsg .= "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
$uploadMsg .= "There was an error: " . error_reporting(2039) . " uploading the file, please try again!";
}
}
?>
<html>
<head><title>Upload File</title></head>
</head>
<body>
<div align="center">
<table width="550" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" class="PageText">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<?php echo $uploadMsg; ?>
</td>
</tr>
<tr>
<td>
<div> </div>
<FORM ENCTYPE="multipart/form-data" ACTION="<?=$_SERVER['PHP_SELF']?>" METHOD="POST">
<INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="30000">
Upload File: <INPUT NAME="uploadedfile" TYPE="FILE"><br />
<INPUT TYPE="SUBMIT" NAME="submit" VALUE="Upload">
</FORM>
<div> </div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
here is what you want
http://www.google.com/search?hl=en&sa=X&oi=spell&resnum=0&ct=result&cd=1&q=PHP+upload+script&spell=1