Upload Image file using Symfony2 without guessers? - symfony

I am using Symfony2 framework for one of my project. In this one, I want to upload an image. This is really easy to do so while following the Symfony2's cookbook. It works very well on my local machine. But when I put the whole application on my remote server (Planethoster.net shared hosting), it doesn't work because of the Type-Mime extension guessers. In fact, they are not enable on their servers... (phpinfo shows --disable-fileinfo)
So, basically the idea is to know if there is a solution to do the same action (uploading an image) without any extension guessers?
Thanks

What do you think of filtering the filename ? With the last three characters, you'll know the extension. Check out UploadedFile, there is a getClientOriginalName() method. What I would do is to explode it by the ., fetch the second entry of the resulting array, and then parse it to do what you want to do.
Would you like an example of code ?

To fix exception while uploading file using framework Symfony 2
Unable to guess the mime type as no guessers are available.
enable PHP extension php_fileinfo, to do this find your php.ini file and uncomment following line
; windows
extension=php_fileinfo.dll
or
; linux
extension=php_fileinfo.so

Related

Imagine library not working in shared hosting

So I was developing a site that needed image resize so I decided to use avalanche123/imagine-bundle which uses the imagine library
In my local everything worked perfectly and then I uploaded the project to a shared hosting
When I go to the url generated by imagine bundle prints a zero
So I tried to find out where the problem is and I found it executes until this line
$image = $this->imagine->open($sourcePath);
$this->imagine is an object with class Imagine\Image\ImagineInterface
So when this line is executed it just returns 0
No exception is thrown and nothing is shown in logs
And I don't really know how imagine works inside and it seems no one else had this problem
So does anyone know what's the cause?
The AvalancheImagineBundle uses the Imagine PHP library to compute images. As stated in the README:
Depending on the chosen Image implementation, you may need one of the
following:
GD2
Imagick
Gmagick
It seems that you can choose the driver with the following configuration:
avalanche_imagine:
driver: gd
The value can be gd, imagick or gmagick and gd seems to be the default. Go ahead and see if any of this three is installed on the shared host by outputting phpinfo();. Just search for the particular string and see if it is avaiable.

Log4j in Websphere

I recently take over a web application project using websphere and log4j running under AIX. To create a development environment, I setup all the components in windows, using eclipse to compile a WAR file and deploy it.
All is working fine except that log file is not created.
I changed the log file in log4j.properties from something like in below and and give everyone full access permission to the directory:
log4j.appender.F1.File=/abc/def/logs/admin.log
to
log4j.appender.F1.File=c:/logs/admin.log
What else can I check?
I create a simple standalone testapp which use the same log4j.properties and it can create the log file, but when the servlet deployed to websphere, it doesn't work. Please help! Thanks!
Ok, I think this article should help you. It seems that WebSphere CE uses log4j by default and controls it with a global properties file. There is a section on how to use application-specific properties files.
Here is what I try and do to troubleshoot similar issues.
Turn on log4j debugging to see where it actually picks up the file from. You need evidence of which file is picked up (so turning the debug on is a worthwhile activity) This provides you information with what log4j is trying to do to locate the configuration file.
-Dlog4j.debug=true
I would not hardcode the log4j location in the code. Instead I
would use the log4j.configuration System property and state that in
the JVM arguments. This way even I don't need to touch my code.
-Dlog4j.configuration=file:///home/manglu/log4j.properties
I would use this approach irrespective of the runtime server that I use (be it Tomcat or WAS CE or WAS)
Hope this helps
I suggest you use environment variables set on your server like this :
You must access the admin console of your server.
Under custom properties
Server_path=/abc/def/logs
In your log4j, use this : {$server_path}/log.txt
Make sure the user running the app has access to that directory.

How to write a webscript in Alfresco that returns a zip file

I need to write a webscript in alfresco that returns to the user a single zip file that contains several files, some of them created on the fly by the script and some of them stored on the server.
How can i do it?I know how to create different files on the server, i don't know how to zip them and how to include files that are stored on the server.
Well, you can develop a Java action that would do the zipping part.
Last time I was looking into this, I didn't find an out-of-the-box solution.
As for returning, you can specify that by specifying webscript format, ie:
<format default="html">any</format>
Only, there is a problem, you can't set a zip format, but alfresco wiki says how you can add more:
http://wiki.alfresco.com/wiki/3.0_Web_Scripts_Framework#HTTP_Response_Formats
Edit: I just found this thread (while looking for a solution for another problem). In the thread a custom "unzip" action is described, maybe you can use that to add a zip/unzip action in your alfresco installation and use it.

web.config - auto generate a release version

Simple task, but for some reason no simple solution just yet.
We've all got web.config files - and I haven't worked anywhere yet that doesn't have the problem where someone yells across the room "Sh*t, I've just uploaded the wrong web.config file".
Is there a simple way of being able to auto generate a web.config file that will contain the right things for copying to release? An example of these being:
Swap connection string over to use live database
Change
Switch over to use the live/release logging system, and live/release security settings
(in our case we need to change the SessionState mode to InProc from StateServer - this isn't normal)
If you have others, let me know and I'll update it here so it's easy for someone else to find
Maintaining 2 config files works, but is a royal pain, and is usually the reason something's gone wrong while you're pushing things live.
Visual Studio 2010 supports something like this. Check it out here.
How are you deploying your builds. In my environment, this used to be a pain point too, but now we use cruisecontrol.net and script our builds in nant. In our script, we detect the environment and have different versions of the config settings for each environment. See: http://www.mattwrock.com/post/2009/10/22/The-Perfect-Build-Part-3-Continuous-Integration-with-CruiseControlnet-and-NANT-for-Visual-Studio-Projects.aspx for my blogpost onthe subject of using cruisecontrol.net for build management. Skip to the end fora brief description of how we handle config versions.
In my most recent project I wrote a PowerShell script which loaded the web.config file, modified the necessary XML elements, and saved the file back out again. A bit like this:
param($mode, $src)
$ErrorActionPreference = "stop"
$config = [xml](Get-Content $src)
if ($mode -eq "Production")
{
$config.SelectSingleNode("/configuration/system.web/compilation").SetAttribute("debug", "false")
$config.SelectSingleNode("/configuration/system.web/customErrors").SetAttribute("mode", "off")
$config.SelectSingleNode("/configuration/system.net/mailSettings/smtp/network").SetAttribute("host", "live.mail.server")
$config.SelectSingleNode("/configuration/connectionStrings/add[#name='myConnectionString']").SetAttribute("connectionString", "Server=SQL; Database=Live")
}
elseif ($mode -eq "Testing")
{
# etc.
}
$config.Save($src)
This script overwrites the input file with the modifications, but it should be easy to modify it to save to a different file if needed. I have a build script that uses web deployment projects to build the web app, outputting the binaries minus the source code to a different folder - then the build script runs this script to rewrite web.config. The result is a folder containing all the files ready to be placed on the production server.
XSLT can be used to produce parameterized xml files. Web.config being xml file this approach works.
You can have one .xslt file(having xpath expressions).
Then there can be different xml files like
1. debug.config.xml
2. staging.config.xml
3. release.config.xml
Then in the postbuild event or using some msbuild tasks the xslt can be combined with appropriate xml files to having different web.config.
Sample debug.config.xml file can be
<Application.config>
<DatabaseServer></DatabaseServerName>
<ServiceIP></ServiceIP>
</Application.config>
.xslt can have xpaths referring to the xml given above.
Can have a look at the XSLT transformation This code can be used in some MSBuild tasks or nant tasks and different web.config's can be produced depending on the input config xml files.
This way you just have to manage the xml files.
There is only one overhead that the xslt file which is similar to web.config need to be managed. i.e whenever there is any tag getting added in the web.config the xslt also needs to be changed.
I don't think you can 100% avoid this.
The last years of work ever and ever shows: where human worked, there are fails.
So, here are 3 ideas from my last company, not the best maybe, but better then nothing:
Write an batch file or an C#.Net Application that change your web.config on a doubleclick
Write a "ToDo on Release"-List
Do pair-realesing (== pair programming while realease :))

ASP.NET MVC - Local Resource Issue

I am having an issue when attempting to override the DisplayNameAttribute in ASP.NET MVC to provide a localized string. The code itself is straightforward and similar to that in another Stackoverflow post link text
The code works for global resources but not so well for local resources. I have a registration screen and used the Visual Studio "Generate Local Resource" command to create my local resource file. The generated file is named Registration.aspx.resx and the App_LocalResources folder is created relative to the actual Registration.aspx page - as one would expect.
However, when I attempt to get the localized string using:
ResourceManager.GetString(resourceKey)
I receive the following error message.
Could not find any resources
appropriate for the specified culture
or the neutral culture. Make sure
"FullAssemblyName.Views.Account.App_LocalResources.Registration_aspx.resources"
was correctly embedded or linked into
assembly "FullAssemblyName" at compile
time, or that all the satellite
assemblies required are loadable and
fully signed.
Using reflector, I can see that the file is actually Registration.aspx.resources and not Registration_aspx.resources - the underscore/period being the subtle difference
FullAssemblyName.Views.Account.App_LocalResources.Registration.aspx.resources
I have toyed with the code quite a bit but no matter what I do, the file being requested is always different than that copiled in the assembly. For instance, if i rename Registration_aspx (in the generated Registration.aspx.designer.cs class i get the same error but this time the path is "...App_LocalResources.Registrationaspx.resources"
Has anyone run into this? Is there any way I can ensure that the resource found in my assembly has this underscore?!?!?
Thank you in advance!
Try Michael K. Campbell solution link text. It worked fine form me in localizing my project.

Resources