//inside banners_controller.php

<?php
class BannersController extends AppController {
        var $name = 'Banners';

       function addbanner() {
                $this->set('showImage', 1);
                if(!empty($this->data)){
                        $screenshotError0 = 
$this->data['Banner']['0']['screenshot']
['error'];
                        $mimeType        = trim($this->data['Banner']['0']
['screenshot']['type']);

                        if ($screenshotError0 == 0) {
                            $screenshot = new File($this->data['Banner']['0']
['screenshot']['tmp_name']);

                            if (!strstr($mimeType,'image')) {
                                $this->set('error', 'Unsupported screenshot 
format
or filesize too large.');
                            } else {
                                $fileName0     = $this->data['Banner']['0']
['screenshot']['name'];
                                $fileName1     = $this->data['Banner']['1']
['screenshot']['name'];
                                $uploadFolder0 = 'files/'.$fileName0;
                                $uploadFolder1 = 'files/'.$fileName1;
                                move_uploaded_file($this->data['Banner']['0']
['screenshot']['tmp_name'],$uploadFolder0);
                                move_uploaded_file($this->data['Banner']['1']
['screenshot']['tmp_name'],$uploadFolder1);
                                if(file_exists($uploadFolder0))  {
                                    $this->set('image0',$fileName0);
                                    $this->set('image1',$fileName1);

                                    /* ADD THESE LINES IN YOUR CODE*/
                                    $this->data['Banner']['name'] = '';
                                    $this->data['Banner']['screenshot'] =
$fileName0;
                                                        
$this->data['Banner']['screenshot1'] = $fileName1;
                                    //$this->data['Banner']['link'] = 
$fileName0;
                                    $this->data['Banner']['link1'] = 
$uploadFolder0;
                                    $this->data['Banner']['link2'] = 
$uploadFolder1;
                                    $this->data['Banner']['date_posted'] = 
time();
                                    $this->Banner->create();
                                    /* ADD THESE LINES IN YOUR CODE*/

                                    $this->Banner->save($this->data);
                                    //$this->set('showImage', 1);
                                     $this->redirect
(array('controller'=>'logins','action'=>'addbanner'));
                                }
                            }

                            if (!empty($fileName0)) {
                                $this->data['Banner']['screenshot_path'] =
$uploadFolder0;
                            } else {
                                $this->data['Banner']['screenshot_path'] = '';
                            }
                        }
                }
                                                $this->set('banners', 
$this->Banner->find('all'));

                        $this ->render('/logins/resources/banners/addbanner');
        }
        function deletebanner($image = null) {
            if (!$image) {
                $this->set('errMsg', 'sorry invalid link');
            } else {
                unlink("files/{$image}");
                //$this->redirect('/uploads/index');
            }
        }

    }

?>




//inside addbanner.ctp

<?php echo $this->element('top_nav1'); ?>


<fieldset width="100%" align="center" cellpadding="0" cellspacing="0"
border="0" class="header">
<table align="center" width="100%" border="0" cellpadding="0"
cellspacing="0">
  <tr>

    <td align="center" valign="top">
        <table width="100%" cellpadding="2"  cellspacing="2"
border="0">
       <tr>
            <td colspan="4" height="32" class="content_text2"
align="center" bgcolor="#CCCCCC" valign="middle">
                <b>RESOURCE CENTRE BANNER </b></td>
          </tr>

    <tr>
        <td align='left' class='text2'>

       *Indicate required fields </td>
          </tr>

<?php echo $this->Form->create('Banner',
array('action'=>'addbanner','type'=>'file'));?>
        <tr height='100'>


           <td>
   <?php
    echo $form->create('Banner', array('action' => 'addbanner', 'type'
=> 'file'));
    echo $form->input('Banner.
0.screenshot',array('type'=>'file','label'=>'Right Banner 1 Photo:'));



         if(($showImage==1)&&(!empty($image0))) {


                 debug($image0);die();

        } ?>
               <?php echo $this->Form->input('link1',
array('label'=>'Right Banner 1 Link: ','style' => 'width:180px;'));?>
           </td>
        </tr>
            <tr>
            <th colspan="2" background="<?php echo $this->webroot; ?
>images/line02.gif"  style="background-repeat:repeat-x;">
                <img src="<?php echo $this->webroot; ?>images/
space.gif"  width="20" height="10"/>

               </th>
          </tr>


            <tr height='20'><td></td></tr>
            <tr>

           <td>
   <?php
    echo $form->input('Banner.
1.screenshot',array('type'=>'file','label'=>'Right Banner 2 Photo:'));


        if(($showImage==1)&&(!empty($image1))) {

            debug($image1);die();
                //echo $html->image('files/'.$image1);
                //echo $html->link('delete','/delete/'.$image1);
        } ?>
           </td>
        </tr>

             <tr><td>
                  <?php echo $this->Form->input('link2',
array('label'=>'Right Banner 2 Link: ','style' => 'width:180px;'));?>

            </td></tr>


             <tr>
            <th colspan="2" background="<?php echo $this->webroot; ?
>images/line02.gif"  style="background-repeat:repeat-x;">
                <img src="<?php echo $this->webroot; ?>images/
space.gif"  width="20" height="10"/>

               </th>
          </tr>


                 <tr>
        <td></td>
          </tr>


            <tr ><table width="60%" align="left" border="0" ><tr>
            <td width="20%"align="right"><?php echo $this->Form-
>button('Reset', array('type'=>'reset'));?></td>
            <td width="20%" align='left'><?php echo $form-
>end(__('Submit', true)); ?></td>
        </tr>

        </table>
        </tr>

</table>
        </tr>

       </table>

</fieldset>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to