Why is my file not uploading?
I dont get any errors, but when it gets to the part of is_uploaded_file, is goes false and errors.
Thanks!
if($_POST['submit']){
$stop_exe = FALSE;
$allowed = array("text/csv", "text/comma-seperated-values", "application/csv", "application/excel", "application/vnd.msexcel", "application/vnd.ms-excel", "application/octet-stream", "text/plain");
if($_FILES['file']['size'] > 40960000){
echo "The maximum file size allowed is 40MB. Please try a differnet file.";
exit;
$stop_exe = TRUE;
}
//end size check
$file_type = $_FILES['file']['type'];
if($file_type == ""){ $file_type = "text/plain"; }
if(!in_array($file_type, $allowed)){
echo "The file you are trying to upload is not a valid type for this fuction.<br \><br \>";
echo "Valid extensions are: ";
foreach($allowed as $key => $var){
echo $var." ";
}
echo "<br /><br />Your file type was: ".$file_type;
$stop_exe = TRUE;
exit;
}
if($stop_exe == FALSE){
$path = $site_dir;
$file_tmp_name = $_FILES['file']['tmp'];
$file_name = $_FILES['file']['name'];
$file_error = $_FILES['file']['error'];
if ($file_error > 0)
{
echo 'Problem: ';
switch ($file_error)
{
case 1: echo 'File exceeded upload_max_filesize of '.ini_get('upload_max_filesize'); break;
case 2: echo 'File exceeded max_file_size'; break;
case 3: echo 'File only partially uploaded'; break;
case 4: echo 'No file uploaded'; break;
}
exit;
}
if(is_uploaded_file($file_tmp_name)){
$move_csv = move_uploaded_file($file_tmp_name, $path.$file_name);
if($move_csv){
chmod($path.$file_name, 0644);
} else {
echo "Could not upload ".$file_name." to ".$core_dir."wm"; exit;
}
} else {
echo $file_name." was not uploaded to be moved."; exit;
}
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$start_2 = microtime_float();
$csv_read = fopen($path.$file_name, "r");
while(($data = fgetcsv($csv_read, filesize($path.$file_name)+1, "\t")) !== FALSE){
$csv[] = $data;
}
$row_num = 1;
foreach($csv as $row){
$arrCol = array();
foreach($row as $col){
while(sizeof($row) > 17){ array_pop($row); }
$arrCol[] = mysql_escape_string($col);
}
if($row_num != 1){
mysql_query("INSERT INTO ".$prefix."store_wholesale VALUES ('".implode("','", $arrCol)."')") or die(mysql_error());
}
$row_num++;
}
}
unlink($path.$file_name);
}