Download image using php from protected server

If you want to download image from a website where allow_url_fopen set to false or some other protection applied then you can’t download it with file_put_content() or copy() etc. Using curl and behaving like a user agent can be used to download image to local directory.

$img =''
$newinsrc = 'images/'.time().'.jpg';
$ch = curl_init($img);
$fp = fopen($newinsrc, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);

Codeigniter Multiple File Upload function

An easy function to upload two image by a html form.

function save_images()
        $html = '';
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png|JPEG|jpeg|PNG|GIF|JPG';
        $this->load->library('upload', $config);
        if (!$this->upload->do_upload('pic1'))
            $html .= $this->upload->display_errors();
            $html .='<br />File Not Uploaded';
            $upload_data = $this->upload->data();
            $html .='File Uploaded !<br />';

 if (!$this->upload->do_upload('pic2'))
            $html .= $this->upload->display_errors();
            $html .='<br />File Not Uploaded';
            $upload_data2 = $this->upload->data();
            $html .='File Uploaded !<br />';
        if($this->db->insert('picz', $dat))       
        return $html;
        return 'Failed !';
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="pic1" />

<input type="file" name="pic2" />

<input type="submit" name="subpic" value="upload" />

Send json in HTTP POST request by CURL php

A simple post operation by php curl. And send some json data.

//extract data from the post

//set POST variables
$url = '';
$jsodata='{"to":"foo", "msg":"bar", "token":"blah"}';
$fields_string ="aajgw=".$jsodata;
//open connection
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, 1); // 1 for number of params (aajgw)
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//execute post
$result = curl_exec($ch);
echo $result;

//close connection

Pass data from controller to view in magento

It’s may be very easy for Zend framework user But, I find some magento developer fighting to pass data from controller to view.
In magento you have to create a empty model(if your mod don’t have a varient object model) which extends to varient object. Magento use magic getter magic setter so you can pass value by setAnyname() and getAnyname() thus functions will be auto defines by Zend like many other framework do. :-)

Model file:

Packname_Modulename_Model_Viewinfo extends Varien_Object{


Controller function:

public function indexAction()
  $bla = Mage::getSingleton('Modulename/viewinfo');
  $bla->setMsg("Thank You for your visit!");

Now in your View .phtml file add:

<?php $blas = Mage::getSingleton('Modulename/viewinfo'); ?>
<?php echo $blas->getMsg(); ?>

Nobody beat us Fry us and eat us