PHP File Upload Script
Posted: Thu Jan 14, 2010 6:03 pm
I have been pulling my hair out for the last 2 days trying to get this simple script to work:
uploadform.php:
uploader.php
Very simple code right?
So here's the question? Why doesn't it work!!!
Seriously. This is what bugs me. Not that it doesn't work, but that it works once... randomly. And then never works again. The code hasn't been changed but it has worked once (or twice). ANd then it just stops working.
Why???
Also what does <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
with the value, is that in bytes or kylobyes?
Regards
uploadform.php:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
</body>
</html>So here's the question? Why doesn't it work!!!
Seriously. This is what bugs me. Not that it doesn't work, but that it works once... randomly. And then never works again. The code hasn't been changed but it has worked once (or twice). ANd then it just stops working.
Why???
Also what does <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
with the value, is that in bytes or kylobyes?
Regards