Jump to content

Cake PHP file upload


devilinc

Recommended Posts

when i try to upload a file, the end result is the filename is stored in database table but the file is not uploaded to the images/logo folder and hence my file isnt displayed.....where did i go wrong?

 

my ctp file is

<?php echo $form->create('Customer',array('type' => 'file'));?>
        <div class="definetemplate">
          <div class="templatename">
            <h2>1. Enter Customer Name</h2>
            <p> </p>
          </div>
          <div class="formcontainer">
            <div class="clearfix">

<?php echo $form->input('customer_name', array('label'=>"Customer Name", 'size'=>'60'));?>
            <span id="msgbox" style="display:none"></span></div>
          </div>

           <div class="templatename">
            <h2>2. Monthly Amount Limit </h2>
            <p> </p>
          </div>



	  <div class="formcontainer">
            <div class="clearfix">

             <?php echo $form->input('customer_monthlyamount', array('label'=>"Amount $", 'size'=>'30'));?>
            <span id="msgbox" style="display:none"></span></div>
          </div>



		 <!-- begin input div -->
		 	<div class="templatename">
				<h2>11. Customer Logo </h2>
				<p> </p>
          		</div>

		 	<div class="formcontainer">
            		<div class="clearfix">
				<?php echo $form->input('customer_logo',array('type'=>'file'));?>
			        <span id="msgbox" style="display:none"></span>
				</div>
          		</div>
		 <!-- end input div -->

          <div class="addbtn">
             <!--<input type="image" name="addgroup" value="Add to Database" src="images/addgroupbtn.png" > -->
		 <?php echo $form->button('Add to Database', array('type'=>'image','src'=>'','label' => false));?>

             <!--<a href="#"><img src="images/addtemplatebtn.png" width="116" height="29" align="top" /></a> -->
          </div>
        </div>
      <?php echo $form->end(); ?>

 

my controller function is:

	function admin_customerscreate($id = null){
		ob_start();

	  /*App::import('Vendor', 'SimpleImage', array('file' => 'resize'.DS.'resizeclass.php'));
	$image = new SimpleImage();
	$qShowStatus = $this->Customer->query("SHOW TABLE STATUS LIKE 'customers'");
	//	print_r($qShowStatus);
		$id_val =$qShowStatus[0]['TABLES']['Auto_increment'];*/
		  if (!empty($this->data))
		 {
			/*if(is_uploaded_file($this->data['Customer']['customer_logo']['tmp_name']))
			  {
				  $ori_name=$id_val."-".$this->data['Customer']['customer_logo']['name'];
				  $up_preview =WWW_ROOT.'files/customer/preview/'.$ori_name;
    				  move_uploaded_file($this->data['Customer']['customer_logo']['tmp_name'], $up_preview);
					$image->load($up_preview);
					$image->resize(20,20);
					$image->save(WWW_ROOT.'files/customer/thumb/'.$ori_name);
			  }*/
			$this->Customer->create();
			 $currentdate=date("Y-m-d h:i:s");
			 $this->data['Customer']['customer_createdate']=$currentdate;
		    $this->data['Customer']['customer_status']=1;
		  	$this->data['Customer']['department_id'] = $_SESSION['department_id'];


			$ori_name=$this->data['Customer']['customer_logo']['name'];
			$this->data['Customer']['customer_logo'] = $ori_name;
			$target_path =WWW_ROOT.DS.'images/logo/'.$ori_name;
			move_uploaded_file($this->data['Customer']['customer_logo']['tmp_name'], $target_path);
			/*
			$ori_name=$this->data['Customer']['customer_logo']['name'];
			$up_preview =WWW_ROOT.DS.'files/customer/preview/'.$ori_name;
    			move_uploaded_file($this->data['Customer']['customer_logo']['tmp_name'], $up_preview);
    			*/

			//$target_path = "uploads/";
//				$this->webroot . 'images'/logo/
			//$target_path = WWW_ROOT.DS.'img/'.$this->data['Customer']['customer_logo']['name'];
			//echo 'file name is===>'.$this->data['Customer']['customer_logo'];die();
			//echo $target_path = $this->webroot.'app/webroot/images/logo/'.$this->data['Customer']['customer_logo']['name'];
			 //$up_preview =WWW_ROOT.'/files/realteam/preview/'.$ori_name;
			if ($this->Customer->save($this->data)) {

				  //$data = $this->paginate('Customer');
				//$this->redirect(array('action' => '/customerslist/'.$_SESSION['department_id']));

				  $this->Session->setFlash(__('The Customer has been saved', true));
				   $data = $this->paginate('Customer');
				 	 $this->redirect(array('action' => '/customerslist/'.$data[0]['Customer']['department_id']));
				  unset($_SESSION['department_id']);
				  ob_flush();
			   } else
			   {
				  $this->Session->setFlash(__('The Customer could not be saved. Please, try again.', true));
				  $data = $this->paginate('Customer');
		$this->redirect(array('action' => '/customerscreate/'.$data[0]['Customer']['department_id']));

		}}else{
				$_SESSION['department_id']=$id;
			}

}

 

 

the filename is stored in database table but the file is not uploaded to the images/logo folder and hence my file isnt displayed.....where did i go wrong?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.