Hello all. I am dumbfounded on this one. I have a form which lets me upload a CSV, but it wont upload them.
I dont get any parse or fatal errors and all of the custom errors I am using to debug it are showing the requested variables.
The following script stops telling me that $file_name." was not uploaded to be moved.";
Any help?
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");
$file_name = $_FILES['file']['name'];
if($_FILES['file']['size'] > 2000000){
$msg = "The maximum file size allowed is 2MB. Please try a differnet file.";
$stop_exe = TRUE;
}
//end size check
if(!in_array($_FILES['file']['type'], $allowed)){
$msg = "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: ".$_FILES['file']['type'];
$stop_exe = TRUE;
}
if($stop_exe == FALSE){
$path = $core_dir."wm/";
if(is_uploaded_file($file_name)){
$move_csv = move_uploaded_file($file_name, $path.$file_name);
if($move_csv){
chmod($path.$file_name, 0644);
} else {
$msg = "Could not upload ".$file_name." to ".$core_dir."wm";
}
} else {
$msg = $file_name." was not uploaded to be moved.";
}
$csv_read = fopen($file_name, "r");
$row = 1;
while(($data = fgetcsv($csv_read, filesize($file_name), ',', ';')) !== FALSE){
//start from row 1 to skip headings on row 0
$cols = count($data);
for($c=0; $c<$cols; $c++){
echo $data[$row]." ";
$row++;
}
}
}
}
//start main body of page
echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" enctype=\"multipart/form-data\">";
echo "<center><b>".$msg."</b></center><br /><br />";
echo "<table width=\"70%\" align=\"center\" border=\"0\">";
echo "<tr><td>Select file:</td><td><input type=\"file\" class=\"textbox\" size=\"24\" name=\"file\"></td><td><input type=\"submit\" value=\"Go!\" name=\"submit\" class=\"submit\"></td></tr>";
echo "</table</form>";