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

eZ debug

Timing: Jan 17 2025 23:51:59
Script start
Timing: Jan 17 2025 23:51:59
Module start 'content'
Timing: Jan 17 2025 23:51:59
Module end 'content'
Timing: Jan 17 2025 23:52:00
Script end

Main resources:

Total runtime0.8976 sec
Peak memory usage4,096.0000 KB
Database Queries194

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0061 589.4766180.8203
Module start 'content' 0.00610.7620 770.2969534.2109
Module end 'content' 0.76820.1294 1,304.5078336.7422
Script end 0.8976  1,641.2500 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00420.4657210.0002
Check MTime0.00160.1773210.0001
Mysql Total
Database connection0.00070.081310.0007
Mysqli_queries0.811090.34631940.0042
Looping result0.00180.20501920.0000
Template Total0.873197.320.4366
Template load0.00220.243720.0011
Template processing0.870997.026820.4355
Template load and register function0.00010.011810.0001
states
state_id_array0.00020.027810.0002
state_identifier_array0.00150.162820.0007
Override
Cache load0.00200.22691070.0000
Sytem overhead
Fetch class attribute can translate value0.00120.133130.0004
Fetch class attribute name0.00160.175440.0004
XML
Image XML parsing0.00110.124230.0004
class_abstraction
Instantiating content class attribute0.00000.001040.0000
General
dbfile0.00220.2497270.0001
String conversion0.00000.000830.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
7content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezxmltags/strong.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/strong.tplEdit templateOverride template
5content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 25
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs