Forums / Developer / Error uploading image : A valid image file is required

Error uploading image : A valid image file is required

Author Message

CALMUS Julien

Friday 22 April 2011 7:03:10 am

I have a problem on one of my plateform.

On the admin interface when I create or edit a content with an image. When I validate it I get this message :

"Required data is either missing or is invalid:
Image: A valid image file is required."

To another plateform with the same ez publish configuration. I have no problem. I have no idee.

In ez Publish files I find where the error message come from : ezimagetype.php :

function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
{
$classAttribute = $contentObjectAttribute->contentClassAttribute();
$httpFileName = $base . "_data_imagename_" . $contentObjectAttribute->attribute( "id" );
$maxSize = 1024 * 1024 * $classAttribute->attribute( self::FILESIZE_FIELD );
$mustUpload = false;
if( $contentObjectAttribute->validateIsRequired() )
{
$tmpImgObj = $contentObjectAttribute->attribute( 'content' );
$original = $tmpImgObj->attribute( 'original' );
if ( !$original['is_valid'] )
{
$mustUpload = true;
}
}
$canFetchResult = eZHTTPFile::canFetch( $httpFileName, $maxSize );
if ( isset( $_FILES[$httpFileName] ) and $_FILES[$httpFileName]["tmp_name"] != "" )
{
$imagefile = $_FILES[$httpFileName]['tmp_name'];
if ( !$_FILES[$httpFileName]["size"] )
{
$contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
'The image file must have non-zero size.' ) );
return eZInputValidator::STATE_INVALID;
}
if ( function_exists( 'getimagesize' ) )
{
$info = getimagesize( $imagefile );
if ( !$info )
{
$contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
'A valid image file is required.' ) );
return eZInputValidator::STATE_INVALID;
}
}
else
{
$mimeType = eZMimeType::findByURL( $_FILES[$httpFileName]['name'] );
$nameMimeType = $mimeType['name'];
$nameMimeTypes = explode("/", $nameMimeType);
if ( $nameMimeTypes[0] != 'image' )
{
$contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
'A valid image file is required.' ) );
return eZInputValidator::STATE_INVALID;
}
}
}
if ( $mustUpload && $canFetchResult == eZHTTPFile::UPLOADEDFILE_DOES_NOT_EXIST )
{
$contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
'A valid image file is required.' ) );
return eZInputValidator::STATE_INVALID;
}
if ( $canFetchResult == eZHTTPFile::UPLOADEDFILE_EXCEEDS_PHP_LIMIT )
{
$contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
'The size of the uploaded image exceeds limit set by upload_max_filesize directive in php.ini. Please contact the site administrator.' ) );
return eZInputValidator::STATE_INVALID;
}
if ( $canFetchResult == eZHTTPFile::UPLOADEDFILE_EXCEEDS_MAX_SIZE )
{
$contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
'The size of the uploaded file exceeds the limit set for this site: %1 bytes.' ), $maxSize );
return eZInputValidator::STATE_INVALID;
}
return eZInputValidator::STATE_ACCEPTED;
}

If anybody have an idee you are welcome.

Finally sorry for my English I'm a Frenchy user ;).

Betsy Gamrat

Monday 25 April 2011 5:44:57 am

Possible causes:

Permission issue - eZ can't move the image into the var directory - check the directory and file permissions with ls -la

Configuration issue - the MIME type for the uploaded image isn't on the server as an image

http://httpd.apache.org/docs/current/mod/mod_mime.html

The client PC may also have the image type associated with a different MIME type

Image type - is the image an icon?

More information:

Which eZ version?

Server type/version, MIME settings (/etc/httpd/conf/httpd.conf is a good place to start)

PHP verison

Directory permissions for var directory

Check /etc/httpd/logs/error_log and var/log/error.log

CALMUS Julien

Monday 02 May 2011 1:17:43 am

No the image isn't an icon. It's a PNG file.

eZ version is 4.3.0.

var directory permissions is the first think I check, no problem on it, all permissions available.

PHP 5, Apache 2, I haven't the exact versions because I only have a FTP access on this server.

I didn't find /etc/httpd/ directory on my server (work fine) or on the server which have the image problem. So I can't check MIME setting. Have you an idee how to find this settings?

Thanks a lot