Screen Shot 2016-03-29 at 4.59.26 AM

Get your filezilla password from your mac

Yeah, FileZilla, the major FTP software would put the passwords along with your username,  host  and other info in your computer directory.

So if you lost your FTP credentials and you have been using FileZilla, you can simply retrieve or assist you remember it.

Just go ahead and open options menu from FileZilla, on Mac computer, you can get this by clicking on the FileZilla menu, and look for settings directory and there you would get xml files containing your credentials.

You can grab and use it. In the meantime, if your computer is accessed by others, also know that they can access your FTP information from there.

Loaded Configuration File => (none) Apache not reading php.ini

php.ini is a core file to handle the behavior of PHP and sometimes apache might not pick it and php might not be using and it will create problem.

To resolve this, just see the output of phpinfo first.
Just add the following code snippet in the php file and run it through your server

<?php
phpinfo();

Then look of configuration file (php.ini) path, by default it would be /etc
If you don’t have the file php.ini in that mentioned directory, just look for related ones like php.ini.default or something and just copy that as php.ini and restart your apache.

Failed to Retrieve Share List from Server when connecting unix

I was getting the Failed to Retrieve Share List from Server when I was trying to move files from my mac to mint 13 pc.

I am trying using the existing samba protocol.

Here is how I fixed it.
I just added the ip address of the mac on my hosts file

sudo vi /etc/hosts

this will bring the hosts file. Then add the ip address and the host name of the computer you are trying to communicate.

Say the ip address of the computer you are trying to connect is 192.168.2.5

192.168.2.5 hostname

Then reboot your *nix

sudo reboot
file upload

multiple file upload in Symfony2 example

Multiple File Upload in Symfony framework

I spent decent amount of time to put together the multiple file upload in symfony.

It is not that difficult actually but the problem is there is no direct/easy documentation or tutorial on it.

On the form type where you would build the form, have the files with the type of collection and make its type a file entity. In this case there would be two file types by default.

    public function buildForm(FormBuilderInterface $builder, array $options) 
    {
        /*
         * The file does not need to be added as "file" because it is referred
         * in the validation for File and SF will automatically know it is file.
         */
        return $builder
                ->add("files", 'collection', array(
		    'type'=>new FileType(),
		    'allow_add'=>true,
		    'data'=>array(new BundleEntityFile(),
		    new BundleEntityFile())
		))
                ->add('save', 'submit');
    }

    public function getName()
    {
        return "files";
    }
}

The trick is on adding the files as collection. Initially, we have two file inputs and their type being FileType.

The allow_add is important to be able to add files through javascript.

The javascript would look like:

/*Handling multiple picture upload*/
$('#add_pictures').click(function(){
    var total_files=$("#member_pictures_container li").length;
    var file_label=document.createElement("label");
    file_label.innerHTML="File";
    file_label.for="PhotoAndDescription_files_"+total_files;
    var div_file=document.createElement("div");    
    div_file.appendChild(file_label);
    var picture= document.createElement('input');
    picture.name="PhotoAndDescription[files]["+total_files+"][file]";
    picture.type="file";
    picture.id="PhotoAndDescripton_files_"+total_files;
    div_file.appendChild(picture);
    div_container=document.createElement('div');
    div_container.id="PhotoAndDescription_files_"+total_files;
    div_container.appendChild(div_file);
    var list_element=document.createElement('li');
    list_element.appendChild(div_container);
    $('#member_pictures_container').append(list_element);
});

FileType would look like:

class FileType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        return $builder->add("file", "file");
    }

    public function getName()
    {
        return "filetype";
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class'=>'BundleEntityFile',
            'csrf_protection'=>true,
            'csrf_field_name'=>'_token',
            'intention'=>'file'
        ));
    }
}

 

And the twig file would look like this one

{{form_start(form)}}
    {{ form_errors(form) }}
    {{ form_widget(form.about_member) }}
    • {% for file in form.files %}

 

  • {{ form_errors(file) }} {{ form_widget(file) }}

 

 

{% endfor %} {{form_end(form)}}

Pretty much this will take care of the multiple file handling in symfony2. As I mentioned earlier, it is not that difficult but the lack of documentation has made it so..

Do you know what to check to deploy Symfony app?

What is POST and HTTP-RAW-POST and php input has to do with enctype? Find out here

node js server downloads text/html as file on browser

Those of you who work with webserver, like apache, might already have seen that problem – like the php file that was intended to display content would be downloaded as file.. this has some fix on configuration right..
Now coming to node js, once you install the server like

  1 var http_server=require("http");
  2 http_server.createServer(function(request, response){
  3     response.writeHead(200, {'Content-Type': "text/html"});
  4     response.write("I am listening @port 8896");
  5     response.end();
  6 }).listen(8896);

This should run fine once you run node filename.js where filename.js is the file containing the above code.
but, when you try to run by going to localhost:8896 and in place of seeing the text on your browser, if the browser decided to download the file, give a a careful look at line number 3 to be sure that you have specified correct content type..

Symfony file upload SplFileInfo::get error

Working on Symfony form that has a file upload and got the above error when I try to save it.
The form is build from entity which has the following format:

class MemberFile
{
    /**
     * SymfonyComponentHttpFoundationFileUploadedFile object
     */
    protected $file;
    /**
     * @ORMId
     * @ORMColumn(name="file_id", type="integer")
     * @ORMGeneratedValue(strategy="AUTO")
     */
    protected $fileId;
    
    /**
     * @ORMColumn(type="string", length=255)
     */
    protected $path;
   // additional member variables and getters and setters goes here...
   .....
    public function upload()
    {
        if (null === $this->file)
            return;
        $this->getFile()->move(
                $this->getUploadDir(), $this->file->getClientOriginalName()
        );
        $this->setSize($this->file->getSize());
        $this->setFileType($this->file->guessExtension());
        $this->path=$this->file->getClientOriginalName();
        $this->file=null;
    }
}

And the form is constructed inside the controller in such a way

$member_file=new MemberFile();
        $form=$this->createFormBuilder($member_file)
                ->add("file")
                ->add("save", 'submit')
                ->getForm();

Right after the appropriate action is requested, I called $member_file->upload() after validation to get the above error..

How I solved it..
1. I checked if the file has been properly uploaded despite the error
-> yes it was uploaded
2. Checked if the original tmp file is still intact –
-> NO and BINGO!
Since the file has been moved, the subsequent operations on $this->file can not be done appropriately.
Solution
Just move those operations before you call move file..

    public function upload()
    {
        if (null === $this->file)
            return;
        $this->setSize($this->file->getSize());
        $this->setFileType($this->file->guessExtension());
        $this->path=$this->file->getClientOriginalName();
        $this->getFile()->move(
                $this->getUploadDir(), $this->file->getClientOriginalName()
        );
        $this->file=null;
    }

How to automate http authentication url from php

if you have to download a file from a web address that would trigger a username and password window (http authentication), then here is the trick

$downloaded_content = file_get_contents("http[s]://yourusername:yourpassword@thefiledownloadurl");
file_put_contents('/tmp/tempholder.csv', $downloaded_content);

The line of interest would be the first one with file_get_contents.
Once you get the content, you can perform a lot of things, either use the content as it is, or copy it to file using file object or just simply transfer the content to other file as the example depicts..