Copy link to clipboard
Copied
This code:
$uploader->addValidator('MimeType', false, 'image');
Is throwing up this error:
The mimetype of file 'bryce2.jpg' could not been detected
I get the same error when using the completed script.
My full code at this stage is below:
<?php
if (isset($_POST['upload'])) {
require_once('library.php');
try {
$destination = 'C:/upload_test';
$uploader = new Zend_File_Transfer_Adapter_Http();
$uploader->setDestination($destination);
$uploader->addValidator('Size', FALSE, '50kB');
$uploader->addValidator('MimeType', false, 'image');
$uploader->addValidator('ImageSize', FALSE, array('minheight' => 500, 'minwidth' => 1000));
$success = $uploader->receive();
if (!$success) {
$messages = $uploader->getMessages();
} else {
$filename = $uploader->getFileName(NULL, FALSE);
$messages[] = "$filename uploaded successfully";
}
} catch (Exception $e) {
echo $e->getMessage();
}
}
Copy link to clipboard
Copied
I am using PHP 5.3.0
Copy link to clipboard
Copied
Further in the chapter, on page 325 near the bottom it says: "..try it by deleting the filename extension before uploading. The script renames the file and adds the correct extension."
However, when I try this, I get this error message:
The mimetype of file 'bryce1' could not been detected
This seems related to the error mentioned in my first post. It seems like the Zend Framework is having trouble detecting MIME types.
Copy link to clipboard
Copied
I have the same issue (in the same book) using wamp locally (php version 5.3.0). I looked for answers and tried to activate some php and apache extensions, but wasn't able to solve the problem...
So, both pages 317 and 325 aren't working (everything in relation to MimeType).
Copy link to clipboard
Copied
P.S. David, I'll probably be using your book to teach a Dreamweaver Web Applications with PHP course, so, I would need to have an explanation, if possible, or I'll have to skip this part in the training... Some people will be using wamp on pc and others MAMP on Mac...
Copy link to clipboard
Copied
Any luck with this? I have the same problem. I have the latest version of Zend, working with PHP Version 5.2.11, Mac OSX 10.6.6.
Copy link to clipboard
Copied
No, never received an answer...
The only way to get it to work (in my case, at least) was to remove the validation line:
$uploader->addValidator('MimeType', false, 'image');
In theory, that would mean that I could upload anything, not just images... but if I try to upload something else, I receive the message "The size of image 'forgotten.php' could not be detected"... because we added later a validation about minheight being 50 and minwidth 100... If we remove that line, there's another check later that sends "Unrecognized image type"... So, it looks like even if we don't validate it's an image, other validations restrict to the three image types we specify later on: jpg, gif and png.
Copy link to clipboard
Copied
Hi Loveanie
I've just discovered that the same files -- with nothing changed but the relevant paths (to the Zend library in library.php and to the destination test upload folder in process_upload.php) work just fine on my PC. It doesn't generate an error message with proper image files, and does with non-image files, as it should.
I wonder if this has something to do with my Mac, or with the version of the Zend Framework (which I downloaded from their website very recently) on my Mac? The version of the Zend Framework on my PC is the one that came on the CD with the book.
Loveanie, are you testing this on a Mac or PC?
Next thing, I think I'll test it on the server on my webspace.
Good luck! -- Jeremy
Copy link to clipboard
Copied
I am testing on a PC locally with WAMP, first with PHP 5.3.0 and now 5.3.4.
I use Zend Framework 1.11.0 (it seems), so maybe yes it as to do with the version being more recent than the one from the book, which is 1.10.6... so I would need to check all the change log, but don't have the time to do so...
Copy link to clipboard
Copied
These files work exactly as they should both on my PC and on the server of my webspace, both with the recent Zend Framework and with version 1.10.6-minimal (which came with the book). The problem is definitely something on my Mac. Not sure where to go next, as I need to have it working there, where Dreamweaver is installed.
Copy link to clipboard
Copied
FYI, I got this working on my Mac -- so it's working everywhere now -- by upgrading MAMP to the latest version. I kept all my old databases and of course the entire contents of the htdocs folder, but accepted the new default configuration.
Hope that helps.
Copy link to clipboard
Copied
I'm working along in this section of the book and am experiencing the same problem as well (and on a Mac, therefore using MAMP). Was there ever a concrete solution discovered? Is it a matter of changing or deleting the code or simply upgrading MAMP (which comes at a cost of about $30)?
Copy link to clipboard
Copied
I've spent hours trying to get it to work too, but am happy to give you the solution:
1. In php.ini add php_fileinfo.dll to the list of enabled extensions
extension=php_fileinfo.dll (remove the ';' in front of it).
2. Download GNU file package for windows
get it from here: http://gnuwin32.sourceforge.net/downlinks/file-bin-zip.php
Extract the folder from the archive called shared\file which contains 4 magic files (magic, magic.mgc, magic.mime, magic.mime.mgc).
3. Place these 4 files in a known place - I put it in C:\xampp\php\extras
4. In php.ini find the entry for mime_magic and set the path to the location above and add \magic so in my example it would be mime_magic.magicfile = "C:\xampp\php\extras\magic"
5. You can have the mime_magic.debug set to On or Off - both worked for me!
6. Restart Apache - if you don't know how reboot your PC!
That should have fixed it . You can now continue with Lesson 9 in the book like me.