Right now I'm just trying to get the uploading part worked out. When the form calls the php file to process everything, it works fine, but when I try to pull the form and the php into a single page, it fails to process and doesn't give any error message. The page just refreshes and presents the form again.
Can anyone see anything wrong with my approach here:
Code: Select all
<?php
if(isset($_POST['uploadedfile'])){
// Where the file is going to be placed
$target_path = "uploads/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$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!";
}
}
if (empty($_POST['uploadedfile'])){
echo '<form enctype="multipart/form-data" action="">';
echo '<input type="hidden" name="MAX_FILE_SIZE" value="100000" />';
echo 'Choose a file to upload: <input name="uploadedfile" type="file" /><br />';
echo '<input type="submit" value="Upload File" />';
echo '</form>';
}
?>