Welcome Guest, Not a member yet? Register   Sign In
Uploading image
#1

[eluser]Unknown[/eluser]
Hello, i have code that add images and then generate PDF, i think that code doesnt save images,it just add them in PDF, i want to save them before i add them in PDF so i can latter use them again, here is my code:

View/crate.php

Code:
<form id = 'imageForm' enctype="multipart/form-data" method='post' target='hiddenframe' action='<?=site_url('generate')?>'>
<table>
<tr><td><label for='tabimg'>Landing Image:</label></td><td>&lt;input id='tabimg' type="file" name="imageOne" value="" size="30" accept="image/png, image/x-png, image/jpeg, image/pjpeg, image/pipeg, image/gif, image/bmp, image/x-bmp, image/x-MS-bmp" /&gt;&lt;/td> </tr>
<tr><td><label for='ad1img'>First Image:</label></td><td>&lt;input id='tabimg' type="file" name="ad1" value="" size="30" accept="image/png, image/x-png, image/jpeg, image/pjpeg, image/pipeg, image/gif, image/bmp, image/x-bmp, image/x-MS-bmp" /&gt; </td> </tr>
<tr><td><label for='ad2img'>Second Image:</label></td><td>&lt;input id='tabimg' type="file" name="ad2" value="" size="30" accept="image/png, image/x-png, image/jpeg, image/pjpeg, image/pipeg, image/gif, image/bmp, image/x-bmp, image/x-MS-bmp" /&gt; </td> </tr>
<tr><td><label for='ad3img'>Third Image:</label></td><td>&lt;input id='tabimg' type="file" name="ad3" value="" size="30" accept="image/png, image/x-png, image/jpeg, image/pjpeg, image/pipeg, image/gif, image/bmp, image/x-bmp, image/x-MS-bmp" /&gt; </td> </tr>
<tr><td><label for='ad4img'>Fourth Image:</label></td><td>&lt;input id='tabimg' type="file" name="ad4" value="" size="30" accept="image/png, image/x-png, image/jpeg, image/pjpeg, image/pipeg, image/gif, image/bmp, image/x-bmp, image/x-MS-bmp" /&gt; </td> </tr>
<tr><td><label for='ad5img'>Fifth Image:</label></td><td>&lt;input id='tabimg' type="file" name="ad5" value="" size="30" accept="image/png, image/x-png, image/jpeg, image/pjpeg, image/pipeg, image/gif, image/bmp, image/x-bmp, image/x-MS-bmp" /&gt; </td> </tr>
</table>
&lt;input type='button' id='reportButton' value="Generate" /&gt;
&lt;/form&gt;


controller/

Code:
function generate(){
                    
            require_once 'swift/lib/swift_required.php';

            $this->load->model('graph');                  
            $this->load->library('upload');
            

      
            $images = array();
            $images['imageOne'] = array('path'=>$_FILES['tabimg']['tmp_name'], 'type'=>pathinfo($_FILES['imageOne']['name'], PATHINFO_EXTENSION));
            $images['ad1'] = array('path'=>$_FILES['ad1']['tmp_name'], 'type'=>pathinfo($_FILES['ad1']['name'], PATHINFO_EXTENSION));
            $images['ad2'] = array('path'=>$_FILES['ad2']['tmp_name'], 'type'=>pathinfo($_FILES['ad2']['name'], PATHINFO_EXTENSION));
            $images['ad3'] = array('path'=>$_FILES['ad3']['tmp_name'], 'type'=>pathinfo($_FILES['ad3']['name'], PATHINFO_EXTENSION));
            $images['ad4'] = array('path'=>$_FILES['ad4']['tmp_name'], 'type'=>pathinfo($_FILES['ad4']['name'], PATHINFO_EXTENSION));
            $images['ad5'] = array('path'=>$_FILES['ad5']['tmp_name'], 'type'=>pathinfo($_FILES['ad5']['name'], PATHINFO_EXTENSION));

      
                       //This part i have add to upload images???

            $config['upload_path'] = './uploads/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_width'] = '100';
            $config['max_height'] = '100';
            $this->upload->initialize($config); // Important
            $this->upload->do_upload($images['imageOne']);
            
            $url = $this->graph->generateThis($images);
}


model/

Code:
function generateThis($images=array('imageOne'=>'./images/4.png', 'ad1'=>'./images/4.png','ad2'=>'./images/4.png','ad3'=>'./images/4.png','ad4'=>'./images/4.png','ad5'=>'./images/4.png')){    
                
        
        require_once('fpdf/fpdf.php');
        require_once('fpdi/fpdi.php');
        
        $CI =& get_instance();
    
        $this->load->helper('url');
        
        $pdf =& new FPDI();
        $pdf->AddFont('MyriadPro');

        $pdf->AddPage("L",array(210,300));
        $pagecount = $pdf->setSourceFile('templates/temp1.pdf');
        $tplidx = $pdf->importPage(1, '/MediaBox');
        $pdf->useTemplate($tplidx, 0,0,0,0,true);
        
        $pdf->SetFont('MyriadPro');
        $pdf->SetTextColor(255,255,255);
        $pdf->SetXY(10,17);
        $pdf->Cell(140,15,$business, 0, 0,"C");

        
        $pdf->Image($images['ad1']['path'], 33,80,44,20,$images['ad1']['type']);
        $pdf->Image($images['ad2']['path'], 33,102,44,20,$images['ad2']['type']);
        $pdf->Image($images['ad3']['path'], 33,124,44,20,$images['ad3']['type']);
        $pdf->Image($images['ad4']['path'], 33,146,44,20,$images['ad4']['type']);
        $pdf->Image($images['ad5']['path'], 33,168,44,20,$images['ad5']['type']);
        
        $pdf->Image($images['imageOne']['path'], 159.5,95,108,90,$images['imageOne']['type']);

        $path = "reports/report-".base_convert($n, 10, 36).".pdf";
        
        $pdf->Output($path, "F");
        return base_url().$path;
    }
#2

[eluser]Unknown[/eluser]
I think i make this to upload, now i need to take them from directory if fields are empty




Theme © iAndrew 2016 - Forum software by © MyBB