po3
12-21-2007, 10:31 AM
I cannot seem to get a file upload to work. Can anyone give me an idea of where I'm going wrong?
From what I can tell when the PHP gets executed the first if statement is skipped and switch statement gets executed in case 0. Which I would think means there were no errors, right?
My HTML:
<html>
<head>
<title>File Upload Form</title>
</head>
<body>
This form allows you to upload a file to the server.<br>
<form action="file_upload_processor.php" method="post"><br>
Type (or select) Filename: <input type="file" name="uploadFile">
<input type="hidden" name="MAX_FILE_SIZE" value="25000" />
<input type="submit" value="Upload File">
</form>
</body>
</html>
My PHP:
<html>
<head>
<title>Process Uploaded File</title>
</head>
<body>
<?php
$message = "Before the if : ";
if ( move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
"../uploads/{$_FILES['uploadFile'] ['name']}") ) {
print '<p> The file has been successfully uploaded </p>';
$message .= "In the first if : ";
} else {
$message .= "In the first else : ";
switch ($_FILES['uploadFile'] ['error']) {
case 0:
$message .= "In the switch case0 : ";
print '<p>error was 0</p>';
break;
case 1:
$message .= "In the switch case1 : ";
print '<p> The file is bigger than this PHP installation allows</p>';
break;
case 2:
$message .= "In the switch case2 : ";
print '<p> The file is bigger than this form allows</p>';
break;
case 3:
$message .= "In the switch case3 : ";
print '<p> Only part of the file was uploaded</p>';
break;
case 4:
$message .= "In the switch case4 : ";
print '<p> No file was uploaded</p>';
break;
}
}
echo $message;
?>
</body>
</html>
From what I can tell when the PHP gets executed the first if statement is skipped and switch statement gets executed in case 0. Which I would think means there were no errors, right?
My HTML:
<html>
<head>
<title>File Upload Form</title>
</head>
<body>
This form allows you to upload a file to the server.<br>
<form action="file_upload_processor.php" method="post"><br>
Type (or select) Filename: <input type="file" name="uploadFile">
<input type="hidden" name="MAX_FILE_SIZE" value="25000" />
<input type="submit" value="Upload File">
</form>
</body>
</html>
My PHP:
<html>
<head>
<title>Process Uploaded File</title>
</head>
<body>
<?php
$message = "Before the if : ";
if ( move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
"../uploads/{$_FILES['uploadFile'] ['name']}") ) {
print '<p> The file has been successfully uploaded </p>';
$message .= "In the first if : ";
} else {
$message .= "In the first else : ";
switch ($_FILES['uploadFile'] ['error']) {
case 0:
$message .= "In the switch case0 : ";
print '<p>error was 0</p>';
break;
case 1:
$message .= "In the switch case1 : ";
print '<p> The file is bigger than this PHP installation allows</p>';
break;
case 2:
$message .= "In the switch case2 : ";
print '<p> The file is bigger than this form allows</p>';
break;
case 3:
$message .= "In the switch case3 : ";
print '<p> Only part of the file was uploaded</p>';
break;
case 4:
$message .= "In the switch case4 : ";
print '<p> No file was uploaded</p>';
break;
}
}
echo $message;
?>
</body>
</html>