I have some problem using cakephp while posting input file type, how get the
filename store to database and data file store to directory? i have not
answer yet :(

example :

I have one table : name table_galleries with field id, title, description,
and picture

i want to the data file store to webroot/img/gallery


View Post

<h1>Add Post</h1>
<form method="post" action="<?php echo $html->url('/gallery/add')?>">
    <p>
        Title:
        <?php echo $html->input('Gallery/title', array('size' => '40'))?>
    </p>
    <p>
        Body:
    <?php echo $html->file('Gallery/picture', array('size' => '40'))?>
    </p>
    <p>
        <?php echo $html->submit('Save') ?>
    </p>
</form>


the controller :

$this->Post->save($this->data['Gallery']


I just thinking and try this way, and not work, because i don't know how to
do stored filename to database and store it file content to directory,
please help me, can any one explain to me? how to use cakephp function with
the right way, thank you :(







Note : cause i can understanf, i make function auto insert to solve that
problem but I want solve this with cakephp way not with my additional class
component.

here is my simple component :


class CatsComponent extends Object
{
    var $controller = true;

    function startup(&$controller)
    {
        $this->controller =& $controller;
    }

function copyfile(){
            $field = "";$lfilename="";$i=0;
            if(isset($_FILES)){
               foreach ( $_FILES as $key => $value ) {
                    if(strtolower(substr($value['name'],-4))==".jpg" ||
strtolower(substr($value['name'],-4))==".gif" ||
strtolower(substr($value['name'],-4)==".png")){
                       $newname =
"pic".substr(md5($value['name']),rand(1,5),rand(5,12)).substr($value['name'],-4);
                       $lfilename.=$key."=".$newname.",";
                          if ([EMAIL PROTECTED]
($value['tmp_name'],UPLOAD."/".$newname)):
                             echo "Error,  Copy file failed. Please check
the file...";
                       endif;
                       $i++;
                    }
               }
            }else{
               $lfilename="";
            }
            return substr($lfilename,0,-1);
      }

      function __createobjectModel($model){
               eval("\$obj = \$this->controller->$model;");
               return $obj;
      }


      function AutoFormInsert($model,$ecp='-'){
               // Auto Insert versi pertama, masih kurang fleksibel jg tapi
cukup baik kok, proses insert jd lebih cepet gak usah nulis2 query lg
               //print_r($_POST);exit();
               $field = "";$values="";$filefield="";$filename="";
               foreach ( $_POST as $key => $value ) {
                  if(($value!="" && strtolower($value)!="save" &&
strtolower($value)!="submit" && strtolower($value)!="update") && $key!="mod"
&& (!ereg("_x",$key) && !ereg("_y",$key) && $key!="x" && $key!="y" &&
!ereg("exc_",$key))){
                         $field .= $key.",";
                         $values .=
($value=="now()")?$value.",":"'".$value."',";
                  }
                  array_shift($_POST); //test di non aktifkan
               }
               //print_r($arrField);exit();
               $fileresult=$this->copyfile(); // split filename=abc.jpg
,filename2=def.jpg, ...
               if($fileresult!=""){
                  if(ereg(",",$fileresult)){
                     $arrfile = explode(",",$fileresult);
                     foreach ( $arrfile as $key2 => $value2 ) {
                               $temp = explode("=",$value2);
                               $filefield .= ",".$temp[0];
                               $filename .= ",'".$temp[1]."'";
                     }
                  }else{
                     $temp = explode("=",$fileresult);
                     $filefield = ",".$temp[0];
                     $filename = ",'".$temp[1]."'";
                  }
               }else{
                     $filefield = "";
                     $filename = "";
               }
               $obj = $this->__createobjectModel($model);
               $buildquery = "insert into
".strtolower($obj->table)."(".substr($field,0,-1)."$filefield)
values(".substr($values,0,-1)."$filename)";
               //echo $buildquery;exit();
               $rs=$obj->Query($buildquery);
               return $rs;
      }

function completedDeleteArr($model,$arrid){
             if($arrid){
              $temp_picture = "";$picname = array();$idnya="0!=0";
              $obj = $this->__createobjectModel($model);
              //print_r($obj->_tableInfo->value);
              for($i=0;$i<count($obj->_tableInfo->value);$i++){
                  $this->temp = $obj->_tableInfo->value[$i];
                  foreach( $this->temp as $x => $v ){
                           if(ereg("name",$x)){
                                if(ereg("picture_",$v)){
                                   $temp_picture .= $v.",";
                                   $picname[] = $v;
              }}}}
              foreach ( $arrid as $v ) { $idnya .= " or id = ".$v;  }
              $getpic = "select ".substr($temp_picture,0,-1)." from
".strtolower($obj->table)." where ".$idnya;
              $rs=$obj->query($getpic);
              //echo count($rs);exit();
              for($i=0;$i<count($rs);$i++){
                foreach ($picname as $v){
                       $this->temp = $rs[$i][strtolower($obj->table)];
                       //echo UPLOAD.$this->temp[$v]."<br>";
                       @unlink(UPLOAD.$this->temp[$v]);
                }
              }
              $delquery = "delete from ".strtolower($obj->table)." where
".$idnya;
              $rs=$obj->execute($delquery); }
     }

} // end class

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to