Skip to main content
Known Participant
September 17, 2010
Question

DW CS5 with PHP - page 317 - error?

  • September 17, 2010
  • 5 replies
  • 9615 views

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();
    }
}

This topic has been closed for replies.

5 replies

Participant
October 2, 2011

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)?

Participant
October 4, 2011

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.

Inspiring
November 14, 2010

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...

Jeremy bowmangraphics
Inspiring
February 7, 2011

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.

Inspiring
February 7, 2011

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.

Inspiring
November 14, 2010

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).

BopjoAuthor
Known Participant
September 17, 2010

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.

BopjoAuthor
Known Participant
September 17, 2010

I am using PHP 5.3.0