juanmc Posted August 7, 2013 Share Posted August 7, 2013 Chapter 111 script 11.2 works fine for uploading jpegs, pngs etc & when I add 'application/pdf' for pdf files also. But when I add e.g. 'application/DWG' it doesn't work. What is the correct code to upload file types: DXF, IGES, ACIs etc. please? This is my code: $allowed = array ('application/octet-stream', 'application/zip', 'application/pdf', 'application/dxf', 'application/x-autocad', 'application/x-dxf', 'drawing/x-dxf', 'image/vnd.dxf', 'image/x-autocad', 'image/x-dxf', 'zz-application/zz-winassoc-dxf','application/igs','application/sat','image\pjpeg', 'image\jpeg', 'image\JPG', 'image\X-PNG', 'image\PNG', 'image\png', 'image\x-png',); if (in_array($_FILES['upload']['type'], $allowed)) { Link to comment Share on other sites More sharing options...
margaux Posted August 7, 2013 Share Posted August 7, 2013 Can you show the full name of the file you're trying to upload? Also just to be clear, have you included 'application/DWG' in the $allowed array? Link to comment Share on other sites More sharing options...
juanmc Posted August 7, 2013 Author Share Posted August 7, 2013 Thanks for your help . The file names are: 1343939490.dwg or wel4.dxf. I have been able to upload these files with a different script. I have added 'application/DWG' to the array, but it still doesn't work: $allowed = array ('application/pdf', 'application/DXF','application/dxf', 'application/DWG', 'application/dwg','image/pjpeg', 'image/jpeg', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png',); if (in_array($_FILES['upload']['type'], $allowed)) { Link to comment Share on other sites More sharing options...
Larry Posted August 7, 2013 Share Posted August 7, 2013 The possible MIME types for just .dwg include: application/acad, application/x-acad, application/autocad_dwg, image/x-dwg, application/dwg, application/x-dwg, application/x-autocad, image/vnd.dwg, drawing/dwg. Rather than add all of those, I would start by seeing what the browser is reporting as the MIME type of that particular file (and try this on a couple of browsers). Link to comment Share on other sites More sharing options...
juanmc Posted August 7, 2013 Author Share Posted August 7, 2013 Thanks. I tried all the options but none worked. I don't think it is a browser problem because I can upload these file types using this code: <?php $uploaddir = 'uploads/';$uploadfile = $uploaddir . basename($_FILES['userfile']['name']); echo "<p>"; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n";} else { echo "Upload failed";} echo "</p>";echo '<pre>';echo 'Here is some more debugging info:';print_r($_FILES);print "</pre>"; ?> But it would suit my purposes better to modify script 11.2 Link to comment Share on other sites More sharing options...
StephenM Posted August 7, 2013 Share Posted August 7, 2013 use this function to check the mime type: [it's discussed on page 414 in chapter 13, not chapter 11] $mime_type = finfo_file( finfo_open(FILEINFO_MIME_TYPE), $YOUR_FILE ); I also had some problems with mime types and headers for .ogg files. In the end I couldn't solve it but I will post that as a separate topic at some stage in the future. 1 Link to comment Share on other sites More sharing options...
StephenM Posted August 7, 2013 Share Posted August 7, 2013 Also, perhaps you can point out the differences between the code that worked and the code that didn't work. That should help figure out what the problem is. And by the way, there is a comma here at the end of your array. $allowed = array ('application/pdf', 'application/DXF','application/dxf', 'application/DWG', 'application/dwg','image/pjpeg', 'image/jpeg', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png',); 1 Link to comment Share on other sites More sharing options...
juanmc Posted August 7, 2013 Author Share Posted August 7, 2013 Many thanks, will try that and report back - mime type is application/octet-stream Link to comment Share on other sites More sharing options...
juanmc Posted August 8, 2013 Author Share Posted August 8, 2013 I have not ben able to resolve the issue for uploading .dwg file etc. An alternative solution would be to allow for .zip file uploads, but this is proving problematic also.. I have used the upload_rtf.php file in chapter 13 to check if .zip file are expectable and get a success message, but the following code allows for .pdf upload but not .zip file: $allowed = array ('application/zip', 'application/pdf', 'application/octet-stream', 'application/DWG', ); if (in_array($_FILES['upload']['type'], $allowed)) { Any suggestions gratefully received Link to comment Share on other sites More sharing options...
StephenM Posted August 8, 2013 Share Posted August 8, 2013 Just wondering, why do you leave a comma at the end of your array? Will this cause an error? [ I don't know, anybody elso know?] Link to comment Share on other sites More sharing options...
juanmc Posted August 9, 2013 Author Share Posted August 9, 2013 The comma at the end doesn't seem to have any effect, I removed it anyway, but no success. Link to comment Share on other sites More sharing options...
Larry Posted August 9, 2013 Share Posted August 9, 2013 I believe the comma ends up creating an empty value at the end of the array, but that's a technical answer that may not reflect actual problems caused by this syntax in the real world. The upload_rtf.php script uses the Fileinfo extension to verify a file's type. Are you actually using that or are you just checking the MIME type provided by the browser? Link to comment Share on other sites More sharing options...
juanmc Posted August 9, 2013 Author Share Posted August 9, 2013 Thanks. I used the upload_rtf.php as standalone file to test if a file was acceptable and got a positive result, but when I used the script I posted above the file was not uploaded. I am unsure as to how to check the Mime type via the browser. I also configured the Mime types in the control panel - it doesn't seem to be a configuration problem. Link to comment Share on other sites More sharing options...
Larry Posted August 9, 2013 Share Posted August 9, 2013 The MIME type via the browser (i.e., what the browser identifies as the MIME type) is what you have above: if (in_array($_FILES['upload']['type'], $allowed)) { The upload_rtf.php script uses the Fileinfo extension and has a different syntax. I have no idea what you mean about configuring the MIME types in the control panel. Link to comment Share on other sites More sharing options...
ericp Posted August 9, 2013 Share Posted August 9, 2013 Hi Larry and all, Is there anyway that the Fileinfo extension can verify multiple file's types, but not only a certain one (e.g., == 'text/rtf'). If yes, what does the syntax look like? Regards, Link to comment Share on other sites More sharing options...
Larry Posted August 9, 2013 Share Posted August 9, 2013 First of all, are you running two separate threads for the same issue? Is this the same issue as: http://www.larryullman.com/forums/index.php?/topic/2557-chapter-13-script-133/&do=findComment&comment=15907 ??? Link to comment Share on other sites More sharing options...
ericp Posted August 9, 2013 Share Posted August 9, 2013 yes, because margaux complicated it. Link to comment Share on other sites More sharing options...
Larry Posted August 9, 2013 Share Posted August 9, 2013 If you want to allow for multiple file upload types and use Fileinfo, you can use the in_array() technique but instead of using $_FILES['upload']['type'] for the value to match, you'd use finfo_file($fileinfo, $_FILES['upload']['tmp_name']): if (in_array(finfo_file($fileinfo, $_FILES['upload']['tmp_name']), $allowed)) {... Link to comment Share on other sites More sharing options...
juanmc Posted August 10, 2013 Author Share Posted August 10, 2013 You can add file extension types in the control panel of the hosting server so I added for example Content Type: applicationzip. Bu, as I said this is not the problem. When I used upload_rtf.php, and changed it to: // Check the file: if (finfo_file($fileinfo, $_FILES['upload']['tmp_name']) == 'application/zip') { it retuned file is acceptable, but when I used upload_image with 'application/zip' in the $allowed array it didn't work Link to comment Share on other sites More sharing options...
Recommended Posts