Zend Framework Can't determine mime type of image upload - zend-framework

Hi all I'm trying to upload a image when creating a item in my app, however the action fails returning the following error: The mimetype of file 'mytestimage.jpg' could not be detected.
I've tried adding a Mime Type validator but the error persists, can anyone tell me where I'm going wrong in the code below.
// Image uploads
$images = new Zend_Form_Element_File('images');
$images->setMultiFile(2)
->addValidator('IsImage')
->addValidator('Size',false,'5242880')
->addValidator('Extension',false,'jpg,png,gif')
->addValidator('ImageSize',false,array(
'minwidth' => 250,
'minheight'=>250,
'maxwidth'=>500,
'maxheight'=>500
))
->setValueDisabled(true);
Many thanks in advance.
Graham

I had the same problem.
Zend_Frameworks tries to determine the mimetype in two ways:
First it tries to use the PECL FILEINFO-Extension (which is not installed on every server)
if the extension is not istalled it tries to use mime_content_type (a php function). This function however is deprecated as of php version 5.3
So in this case I guess your hoster is using php version 5.3 and has not installed the PECL FILEINFO-Extension. Same goes unfortunately for my hoster :(
Here are more details of the two ways in the php-manual:
http://de.php.net/manual/en/function.mime-content-type.php
http://de.php.net/manual/en/ref.fileinfo.php
By the way. You can see the code ZF uses in the file "Zend\File\Transfer\Adapter\Http.php" (lines 1281-1318: methodname is _detectMimeType

Related

TYPO3 website doesn't work after changing db

I want to make a copy of my TYPO3 CMS 6.2.18 website - what I did so far:
Copied the entire website folder (including the TYPO3 installation)
Copied the entire database (with a new name)
Created a new db user for the copied db
Adjusted the file /typo3conf/LocalConfiguration.php accordingly to the new DB+User
Now I'm receiving following errors when calling different urls of my copied TYPO3 website:
When I try calling the "Upgrade Wizard" from inside the install tool /typo3/install (which is the only page that currently works):
#1: PHP Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/vhosts/<my-domain>/typo3/sysext/install/Classes/Service/SqlSchemaMigrationService.php line 409
When I call <my-domain>/typo3
#1: PHP Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/vhosts/<my-domain>/typo3/sysext/backend/Classes/Utility/BackendUtility.php line 3022
4 count(NULL)
...
/var/www/vhosts/<my-domain>/typo3/sysext/backend/Classes/Utility/BackendUtility.php:
03020: $signals = array();
03021: $modData = $GLOBALS['BE_USER']->getModuleData('TYPO3\\CMS\\Backend\\Utility\\BackendUtility::getUpdateSignal', 'ses');
03022: if (!count($modData)) {
03023: return '';
03024: }
When I call <my-domain>
#1: PHP Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/vhosts/<my-domain>/typo3/sysext/core/Classes/Database/PreparedStatement.php line 582
...after calling...
TYPO3\CMS\Core\Database\PreparedStatement::convertNamedPlaceholdersToQuestionMarks("SELECT * FROM fe_session_data WHERE hash = :hash", array, array)
What's interesting to me:
After copying the website the copy worked, only after referencing it to the copied db it showed these errors.
Anyone an idea what I could do / be looking for?
I tried deleting all cache, all tables shown in the "Cleanup" part of the install tool and all files in the typoe3temp folder already.
So, as I have said in the comment. Probably the issue with PHP version, because of all the mentioned errors (warning actually ;) ) reflect the incompatible PHP code.
The solution is pretty easy, switch your PHP version according to TYPO3's need :)

Zend Framework with Handwritten Font

I am trying to use the Amatic Font from Google in my PDF File but it gives me an Error like below. Could that be because the Font Type? I have tested with Open Sans and it is working.
AH01071: Got error 'PHP message: PHP Fatal error: Uncaught exception
'Zend_Pdf_Exception' with message 'Unable to read version 4 table' in
/var/www/vhosts/httpdocs/main/zend/library/Zend/Pdf/FileParser/Font/OpenType.php:555\nStack
trace:\n#0
/var/www/vhosts/httpdocs/main/zend/library/Zend/Pdf/FileParser/Font/OpenType.php(121):
Zend_Pdf_FileParser_Font_OpenType->_parseOs2Table()\n#1
/var/www/vhosts/httpdocs/main/zend/library/Zend/Pdf/FileParser/Font/OpenType/TrueType.php(83):
Zend_Pdf_FileParser_Font_OpenType->parse()\n#2
/var/www/vhosts/httpdocs/main/zend/library/Zend/Pdf/Font.php(701):
Zend_Pdf_FileParser_Font_OpenType_TrueType->parse()\n#3
/var/www/vhosts/httpdocs/main/zend/library/Zend/Pdf/Font.php(615):
Zend_Pdf_Font::_extractTrueTypeFont(Object(Zend_Pdf_FileParserDataSource_File),
0)\n#4 /var/www/vhosts/httpdocs/main/zend/invoice.php(27):
Zend_Pdf_Font::fontWithPath('/var/www/vhosts...')\n#5 {main}\n\nNext
exception 'Zend_Pdf_Exception' wi...\n'
I am using this Script for my tests https://github.com/phpmasterdotcom/GeneratingInvoicesWithZendPdf/blob/master/public/invoice.php
What's happening is this: The Zend Framework code in OpenType.php explicitly checks the OS/2 table version of the font. Is it higher than 3, an exception is thrown. Your font has an OS/2 table version of 4 (which is the fifth version, there are at least 6 versions as far as I know).
Unfortunately, recent versions of the ZendPdf module (like here on GitHub) still don't seem to support version 4 or higher. So apart from looking for another pdf generator - that does support version 4 - I fear there's no clean solution.
You could try editing the framework code, but of course that's a bit shady. As an alternative, apparently it should be able to change that version and regenerate the font. See this post on the Tex forum (the post AFTER the accepted answer). If you choose that path, probably you'll find better guidance on that forum.
Sorry I can't offer a better solution, but maybe it helps you understanding what's going on.

Birt Multi Sheet report using SpudSoft

I´m having some problems to create reports in my server without default export engine.
I´m using SpudSoft to create it. I have the following configuration:
Tomcat 7
Birt 4.2.2
uk.co.spudsoft.birt.emitters.excel_0.8.0.201310230652.jar
And i followed this tutorial:
spudsoft-birt-excel-emitters
I haven´t include this file
lib/slf4j-api-1.6.2.jar
because it´s not included in the *.jar file
and either wrote this code:
'if( "XLS".equalsIgnoreCase( outputFileFormat ) ) {
renderOption.setEmitterID( "uk.co.spudsoft.birt.emitters.excel.XlsEmitter" );
} else if( "XLSX".equalsIgnoreCase( outputFileFormat ) ) {
renderOption.setEmitterID( "uk.co.spudsoft.birt.emitters.excel.XlsxEmitter" );
}'
Because I dont really know where to use it.
to run my report i use the following URL
http://127.0.0.1:8090/birt-viewer/frameset?__format=xls&__report=informes/myReport.rptdesign&__emitterid=uk.co.spudsoft.birt.emitters.excel.XlsEmitter
and i get the following message:
org.eclipse.birt.report.service.api.ReportServiceException: EmitterID uk.co.spudsoft.birt.emitters.excel for render option is invalid.
What can i do to run SpudSoft report? I've been reading for a week and I haven´t found any solution!
Thanks a lot for all!
#Dominique,
I recommend upgrading from the emitter included with BIRT 4.3 (and given the lack of responses from the BIRT team I regret letting them put it in there).
Also, you don't need to use a specific IRenderOption type - they are all the same really anyway.
#Jota,
If you are getting that error it means that BIRT hasn't picked up the emitter correctly (you do have the correct emitter ID).
I don't use the BIRT war file, so my instructions aren't aimed at that approach (I just use the report engine in my own service).
The code snippet is no use for you, it's just a way to specify the emitter ID, which you are doing on the query string.
slf4j shouldn't be needed with the version of the emitter that you have - it uses JUL instead (I hate JUL, but it's one fewer dependency).
Can you post a complete listing of the jar files in your war?
It seems because you make use of a generic IRenderOption. With spudsoft emitter you should instantiate your render options like this:
EXCELRenderOption excelOptions = new EXCELRenderOption();
Note if you upgrade to BIRT 4.3 you don't have to set the emitter anymore, it is embedded

How could I embedded socket in Lua internally, just like oslib, debuglib?

I want to implement the function like embedding the socket function in my Lua build.
So I don't need to copy socket.core.dll any more (just for fun).
I search the maillist, and see some guys discuss the topic,
http://lua-users.org/lists/lua-l/2005-10/msg00269.html
But I have question for the details steps, who could give me a detailed steps for changing the lua and luasocket code to make them work together (not with dll method).
I tried these steps in windows xp with VC2008:
1) copy luasocket code to Lua project.
2) add some code
static const luaL_Reg lualibs[] = {
{"", luaopen_base},
{LUA_LOADLIBNAME, luaopen_package},
{LUA_TABLIBNAME, luaopen_table},
{LUA_IOLIBNAME, luaopen_io},
{LUA_OSLIBNAME, luaopen_os},
{LUA_STRLIBNAME, luaopen_string},
{LUA_MATHLIBNAME, luaopen_math},
{LUA_DBLIBNAME, luaopen_debug},
{LUA_SOCKETLIBNAME, luaopen_socket_core}, // add this line
{LUA_MIMELIBNAME, luaopen_socket_core}, // add this line
{NULL, NULL}
};
3) build the project, and run it.
When I type print(socket._VERSION), it shows luasocket 2.0.2, it is correct.
When I type print(socket.dns.toip("localhost")), it shows 127.0.0.1 table: 00480AD0, it is correct too.
But when I try to use other features, for example bind, it can't work.
Who could tell me the reason?
you need put luasocket stuff into the package.preload table, in this way:
lua_getfield(L, LUA_GLOBALSINDEX, "package");
lua_getfield(L, -1, "preload");
lua_pushcfunction(L, luaopen_socket_core);
lua_setfield(L, -2, "socket.core");
// add mime.core yourself...
luasocket is a mixed C/lua module, you need to bundle both versions into your application if you want it to work without any extra files.
socket.lua loads socket.core (from socket/core.dll)
mime.lua loads mime.core (from mime/core.dll)
So in order for your application to work you will need to build all the .dll files and the .lua files into your application and manually load them (or set them up to be loaded correctly via custom package loaders).
The email you quoted is tweaking the package.preload table (in a way that appears a tad odd now but might work anyway) to get the built-in C code to be loaded correctly when require is called.
Try running
for k, v in pairs(socket) do print(k, v) end
and maybe we'll be able to help.

Enterprise Library 4: logging block flat file

I am having problem creating log entry to a text file. Here is my logging configuration in my ASP.net app.
and here is my vb.net code
Try
db.ExecuteNonQuery(cmd, tr)
tr.Commit()
result = True
Catch ex As Exception
Dim entry As New LogEntry()
entry.EventId = 11
entry.Message = ex.Message
entry.Categories.Add("General")
Logger.Write(entry)
tr.Rollback()
End Try
All the tutorial and example that i found so far are based on older version of Enterprise Library. I'm using Enterprise Library 4. Does anyone know what i'm doing wrong? Is it my code or the configuration? Where can i find more tutorial on Enterprise Library version 4. I tried to follow the quick start that it come with but i can't make head or tail.
its a basic tutorial on using enterprise library 4.1
http://blog.accentient.com/EnterpriseLibraryLogging101.aspx
btw, to get mine to work, i had to change all the PublicKeyToken's to = null
otherwise the web.config didnt validate, gl