image vs .doc upload
Posted: Tue Jan 06, 2004 9:40 am
I have a file upload script that works fine when I upload images, but will not work if I try to upload a MS word document, can someone please take a look at my code and tell me what I am doing wrong:
Here is the original image upload script:
Here is the changed code for the MS word upload:
All I changed was the $path and image/gif to text/plain.
HELP!
Thank you,
Here is the original image upload script:
Code: Select all
<?php
$path = "/usr/local/psa/home/vhosts/xxxx.org/xxxdocs/xxxxx/images/";
$max_size = 200000;
if (!isset($HTTP_POST_FILES['userfile'])) exit;
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {
if ($HTTP_POST_FILES['userfile']['size']>$max_size) { echo "<b>The file is too big</b><br><br>\n"; exit; }
if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg")) {
if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { echo "The file already exists<br>\n"; exit; }
$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path .
$HTTP_POST_FILES['userfile']['name']);
if (!$res) { echo "<b>upload failed!</b><br><br>\n"; exit; } else { echo "<b>Upload Successful</b><br><br>\n"; }
echo "File Name: ".$HTTP_POST_FILES['userfile']['name']."<br>\n";
echo "File Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\n";
echo "File Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\n";
} else { echo "<b>Wrong file type</b><br><br>\n"; exit; }
}
?>Code: Select all
<?php
$path = "/usr/local/psa/home/vhosts/xxxx.org/xxxdocs/xxxApplication/resume/";
$max_size = 200000;
if (!isset($HTTP_POST_FILES['userfile'])) exit;
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {
if ($HTTP_POST_FILES['userfile']['size']>$max_size) { echo "<b>The file is too big</b><br><br>\n"; exit; }
if (($HTTP_POST_FILES['userfile']['type']=="text/plain")) { {
if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { echo "The file already exists<br>\n"; exit; }
$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path .
$HTTP_POST_FILES['userfile']['name']);
if (!$res) { echo "<b>upload failed!</b><br><br>\n"; exit; } else { echo "<b>Upload Successful</b><br><br>\n"; }
echo "File Name: ".$HTTP_POST_FILES['userfile']['name']."<br>\n";
echo "File Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\n";
echo "File Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\n";
} else { echo "<b>Wrong file type</b><br><br>\n"; exit; }
}
?>HELP!
Thank you,