Greetings once again,
I've posted this problem three times to different message boards and so far I've gotten help but no solutions. Before, it was only happening with images, now it's happening with all files on the form posted in the reply to this message. Below I've "attached" two files. The first is the upload_resume.php which contains the <form> that the user will use to search for and upload their resume. The second file is the process that takes the uploaded file and is named pro_upload_resume.php.
Here's the symptoms. In Internet Explorer, you can search for and find a file using the browse button created by the <input type="file"> field. Then, when you click the upload button you are sent to the process page (second pagebelow) but the browser displays a page cannot be displayed error and the title of the page is "Cannot find server." However, I was just on the server for the previous file so that seems pretty mysterious to me.
In FireFox, Mozilla, and Netscape when you click the upload button nothing happens at all. You don't go to the process page, you don't get any error messages. It's as if the <input type="submit"> button is just an <input type="button"> button with no associated actions.
On a Mac with Safari, I receive the message "Safari can't open the page ... because it could not load any data from this location."
However, when I used an extremely small .htm file (<10kb) it worked and correctly gave me an error saying that the file was not a .pdf file, which is what I want to happen. Why does this work with some files but not others.
In php.ini the max upload file size is set to 2 MB and I've tried to use the MAX_FILE_SIZE hidden input field to set the max for this file at 1 MB. I assume that MAX_FILE_SIZE is in bytes so 1 MB is 1000000 for the value of MAX_FILE_SIZE but perhaps I'm wrong and I can't find docuentation on that anywhere.
So, any ideas why the form below uploads some files but not all files and when it doesn't upload files it doesn't seem to do anything? I've been pulling my hair out over applications like these now for about a month and I've gotten nowhere.
Hoping you can help me,
-- Dave --
Still Can't Upload Some Files
Moderator: General Moderators
Code: Select all
<form method="post" action="pro_upload_resume.php" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<strong>Resume File</strong>: <input type="file" name="resume" size="50" class="bodytext"><br>
<input type="submit" class="bodytext" value="Upload Resume">
</form>Code: Select all
list($name, $type, $tmp_name, $error, $size) = array_values($_FILES['resume']);
if($error == UPLOAD_ERR_INI_SIZE || $error == UPLOAD_ERR_FORM_SIZE || $error == UPLOAD_ERR_PARTIAL) {
// for these codes, we'll just pass the error code onto the other page because we can match them against the
// PHP error codes for easy error messages.
$_SESSION['error'] = $error;
header("Location: upload_resume.php?code=error");
exit;
} else {
if(!empty($tmp_name) && $tmp_name!="none") {
if($type != "application/pdf" && $type != "application/x-pdf") {
$_SESSION['error'] = "BAD TYPE";
header("Location: upload_resume.php?code=error");
exit;
} else {
$file_name = str_replace("", "/", $name); // replace \ with / from windows in client-side name
$file_name_parts = explode("/", $file_name); // explode the file name into tokens on the / as a delimiter
$file_name = $file_name_parts[count($file_name_parts)-1]; // the last array member is filename.extension
$file_name = str_replace(" ", "_", $file_name); // replace spaces with underscores for old browser support
$abs_file_name = $_SERVER['DOCUMENT_ROOT'] . "media/pdfs/uploads/resumes/" . $file_name;
while(file_exists($abs_file_name)) {
$file_name_parts = explode(".", $file_name); // split the file name from its extension
$random_num = mt_rand(1, 1000000); // get a random number between one and a million
$file_name_parts[0] .= "_" . $random_num; // append the random number to the file name
$file_name = join($file_name_parts, "."); // put the file name back together again
$abs_file_name = $_SERVER['DOCUMENT_ROOT'] . "media/pdfs/uploads/resumes/" . $file_name;
} $moved = move_uploaded_file($tmp_name, $abs_file_name);
if(!$moved) {
$_SESSION['error'] = "NOT MOVING";
header("Location: upload_resume.php?code=error");
exit;
}
}
}
}-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
With Mozilla, FireFox, Netscape, and Safari, when you submit the form you stay on the same page. Therefore the URL doesn't change at all.kettle_drum wrote:What is in the url when you submit the form?
With IE, you do go to the process page correctly and it is the correct process page.
If you simply navigate to the process page without using the form, you correctly receive an error message that tells you that there was no input from the form and to return to the form and upload a file.What is the url in the browser when you simply open the page with the php code in a second window - without using the form?
SometimesDo these url's match?
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England