After using my script to upload files, some file types will become corrupt. PDF's work fine, text/html works fine..but files such as JPG/GIF/DOC, etc...become corrupt.
I am assuming this is a binary vs ascii issue and would like some help?
I've looked around for an answer to this and cannot find anything.
Here is my code:
if($HTTP_POST_FILES['userfile']['name'] <> "") {
//Process uploaded form
$uploadDir = $HTTP_SERVER_VARS['DOCUMENT_ROOT'] . '/documents/';
$uploadFile = $uploadDir . $HTTP_POST_FILES['userfile']['name'];
$fileName = $HTTP_POST_FILES['userfile']['name'];
$fileExist = mysql("$database", "select id from documents where fileName = '$fileName'");
$fileExist_rows = mysql_num_rows($fileExist);
if ($fileExist_rows > 0) {
echo "<font color=\"red\">The file '" . $fileName . "' already exists.</font>";
}else{
if (move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], $uploadFile)) {
echo "<font color=\"red\">Your document '". $HTTP_POST_FILES['userfile']['name'] . "' has been uploaded.</font>";
$add_doc = mysql("$database","insert into documents values('', '$description', '$fileName')");
}else{
print_r($HTTP_POST_FILES);
}
}
}else{
echo "<font color=\"red\">You must choose a file to upload.</font>";
}
I am assuming this is a binary vs ascii issue and would like some help?
I've looked around for an answer to this and cannot find anything.
Here is my code:
if($HTTP_POST_FILES['userfile']['name'] <> "") {
//Process uploaded form
$uploadDir = $HTTP_SERVER_VARS['DOCUMENT_ROOT'] . '/documents/';
$uploadFile = $uploadDir . $HTTP_POST_FILES['userfile']['name'];
$fileName = $HTTP_POST_FILES['userfile']['name'];
$fileExist = mysql("$database", "select id from documents where fileName = '$fileName'");
$fileExist_rows = mysql_num_rows($fileExist);
if ($fileExist_rows > 0) {
echo "<font color=\"red\">The file '" . $fileName . "' already exists.</font>";
}else{
if (move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], $uploadFile)) {
echo "<font color=\"red\">Your document '". $HTTP_POST_FILES['userfile']['name'] . "' has been uploaded.</font>";
$add_doc = mysql("$database","insert into documents values('', '$description', '$fileName')");
}else{
print_r($HTTP_POST_FILES);
}
}
}else{
echo "<font color=\"red\">You must choose a file to upload.</font>";
}