Hey guys... I'm trying to upload a CSV file via form. Im trying to limit my filetypes to only CSV...but it is not letting me upload.. I can do it fine with jpeg/gif etc but not csv.. any ideas? check out my code please: $types = array('image/jpeg', 'text/csv'); $target_path = "data/uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if (in_array($_FILES['uploadedfile']['type'], $types)) { if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { $success = "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded successfully."; } else{ $error = "<img src=\"../images/error-1.png\">" . " There was an error uploading the file, please try again!"; } } else { $error = "<img src=\"../images/error-1.png\">" . " You can only upload a CSV file! " . "<strong><a href=\"update.php\">Try Again</a></strong>"; } echo "Upload: " . $_FILES["uploadedfile"]["name"] . "<br />"; echo "Type: " . $_FILES["uploadedfile"]["type"] . "<br />"; echo "Size: " . ($_FILES["uploadedfile"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["uploadedfile"]["tmp_name"]; When i upload a photo, all my echos work fine, and it moves the file to my server. When i try to upload a CSV it does not move the file and gives me my error. Any ideas? Thanks, -Tim
I just added 'text/comma-separated-values' as part of the array and it successfully uploaded the file. BUT it was a brand new CSV I made in excel. It will still not upload the CSV that I want... Is it a specific csv type i need to allow? im so confused... ugh.
They are often coded as plain text "text/plain" and not "text/comma-separated-values". Not sure if that's a problem, but if it isn't from excel it may have a different content type.