ill-fated24 Posted June 13, 2013 Share Posted June 13, 2013 Hi everyone, I got trouble uploading a csv file in php. Cant seem to figure out whats wrong, it always lead me to "nicetry" even though im sure im uploading a csv file. upload_page <?php echo "<form action='upload_process.php' id='upload_form' method='post' enctype='multipart/form-data'>"; echo "<table id='class1' align='center'>"; echo "<tr>"; echo "<th colspan=2>Upload</th>"; echo "</tr>"; echo "<tr>"; echo "<td colspan=2><input type='file' name='file' id='file' size='50'/></td>"; echo "</tr>"; echo "<tr class='alt'>"; echo "<td colspan=2><input type='submit' name='upload' value='upload' /></td>"; echo "</tr>"; echo "</table>"; echo "</form>"; ?> upload_process $mimes = array('application/vnd.ms-excel','text/plain','text/csv','text/tsv'); if(in_array($_FILES['file']['type'],$mimes)){ echo "csv file!"; } else { echo "nicetry"; } any input would be very much appreciated. thanks! Quote Link to comment Share on other sites More sharing options...
Barand Posted June 13, 2013 Share Posted June 13, 2013 (edited) What is in $_FILES['file']['type'] ? What does $_FILES['file']['tmp'] contain? Edited June 13, 2013 by Barand Quote Link to comment Share on other sites More sharing options...
ill-fated24 Posted June 13, 2013 Author Share Posted June 13, 2013 (edited) It should be the file uploaded from the upload_page. Edited June 13, 2013 by ill-fated24 Quote Link to comment Share on other sites More sharing options...
ill-fated24 Posted June 13, 2013 Author Share Posted June 13, 2013 (edited) Sorry for the double post. Im having trouble with my internet connection. I've also tried the below code for upload_process. Keeps throwing me this is not a csv file. if (($_FILES["file"]["type"] == "application/vnd.ms-excel")) { if ($_FILES["file"]["error"] > 0) { echo "error uploading the file"; } else { echo "hooray!"; } } else { echo "this is not a csv file"; } Man this one problem got me searching for answers for like a day already. Edited June 13, 2013 by ill-fated24 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted June 13, 2013 Share Posted June 13, 2013 It should be the file uploaded from the upload_page. Barand's questions weren't about what the values should be, but were for you to look at what the values actually are. because your code is testing what the values are and your code is detecting that they aren't what you expect, knowing what they actually are would point to the cause of the problem. stated another way, your code is trying to use data values that would only be present for a successful upload, before your code has even tested that the upload worked. check if the upload worked first, then try to test the data values from the upload. for a successful upload, $_FILES["file"] will be set and $_FILES["file"]['error'] will be equal to a zero. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.