2015-01-09 24 views
7

Klasöre yüklenen dosyaların sayısıyla ilgili bir kod var ve bu dosyaların adını, boyutunu ve URL'sini veritabanında istiyorum ancak Denetleyicim çalışmıyor. (CakePHP çerçevesini kullanıyorum). Veritabanına ne yüklediğimi bu dosya verilerini eklemek istiyorum (tüm dosya verileri) ve hatayı aldım.Yüklenen dosyadaki veriler

Hata:

Notice (8): Undefined index: tmp_namā€ā€‹ā€ā€‹e [APP\Controller\UploadFilesController.php, line 24] 

burada

public function uploadFile() { 
     $filename = ''; 
      if ($this->request->is('post')) {   // checks for the post values 
       $uploadData = $this->request->data; 
       //print_r($this->request->data); die; 
       foreach($uploadData as $file){ 
       $filename = basename($file['name']); // gets the base name of the uploaded file 
       $uploadFolder = WWW_ROOT. 'files'; // path where the uploaded file has to be saved 
       $filename = $filename; // adding time stamp for the uploaded image for uniqueness 
       $uploadPath = $uploadFolder . DS . $filename; 
       if(!file_exists($uploadFolder)){ 
        mkdir($uploadFolder); // creates folder if not found 
       } 
       if (!move_uploaded_file($file['tmp_name'], $uploadPath)) { 
        return false; 
       } 
       echo "Sa sisestasid faili: $filename<br>"; 
      } 
      foreach($this->request->data['UploadFile']['file_upload'] as $file){ 
       if (!empty($this->request->data) && is_uploaded_file($this->request->data['UploadFile']['file_upload']['tmp_nam‌​‌​e'])) { //THIS IS LINE 24 
        $fileData = fread(fopen($this->request->data['UploadFile']['file_upload']['tmp_name'], "r"), $this->request->data['UploadFile']['file_upload']['size']); 
        $this->request->data['UploadFile']['name'] = $this->request->data['UploadFile']['file_upload']['name']; 
        $this->request->data['UploadFile']['size'] = $this->request->data['UploadFile']['file_upload']['size']; 
        $this->request->data['UploadFile']['URL'] = $this->request->data['UploadFile']['file_upload']['tmp_name']; 
        $this->request->data['UploadFile']['data'] = $fileData; 
        $this->UploadFile->create(); 
        $this->UploadFile->save($this->request->data); 
       } 
      } 
     } 
    }  
    } 

Ve My Denetleyici benim Görünüm dosyasıdır:

<?php 
    echo $this->Form->create('uploadFile', array('type' => 'file')); 
?> 

    <div class="input_fields_wrap"> 

     <label for="uploadFilefiles"></label> 
     <input type="file" name="data[]" id="uploadFilefiles"> 

    </div> 

<button type="button" class="add_field_button">+</button> <br><br> 

    <form name="frm1" method="post" onsubmit="return greeting()"> 
     <input type="submit" value="Submit"> 
    </form> 

<?php 
echo $this->Html->script('addFile'); 

Gerekirse ben de AddFile senaryoyu ekleyebilir .

enter image description here

cevap

5

, bu bunu yapmanın en iyi yoludur.

+0

Evet, çalışıyor. Teşekkür ederim ! – frantsium

+0

Ödülünü 22 saat içinde verebilirsiniz. Üzgünüm – frantsium

+2

Sorun değil. Yardım ettiğime sevindim. – hammasta

1

Sen görünümünde değişiklik: İşte

benim tablodur yapıyı ( upload_files)

<input type="file" name="data[UploadFile][file_upload][]" class="form-control" multiple="multiple" id="AuthorAuthorImage"> 

Ve kontrolör Eğer Bu veriler

$this->request->data['UploadFile']['file_upload'] 

olduğunu olsun dizi biçimi ile birlikte:

array (
[0] => Array 
(
    [name] => 0.jpg 
    [type] => image/jpeg 
    [tmp_name] => D:\xampp\tmp\php5896.tmp 
    [error] => 0 
    [size] => 55125 
) 

[1] => Array 
(
    [name] => 1.jpg 
    [type] => image/jpeg 
    [tmp_name] => D:\xampp\tmp\php5897.tmp 
    [error] => 0 
    [size] => 49613 
) 

[2] => Array 
(
    [name] => 1-16.png 
    [type] => image/png 
    [tmp_name] => D:\xampp\tmp\php58A7.tmp 
    [error] => 0 
    [size] => 1545337 
) 
) 

İyi şanslar! tungbk29 olarak

+0

Evet, ama ben bu çoklu girişte kullanmıyorum, yeni girdiler yapan komut dosyası kullanıyorum. – frantsium

+0

tungbk29

+0

bu satırı kullanmazsınız. Eğer (! Empty ($ this-> request-> data) && is_uploaded_file ($ this-> request-> data ['UploadFile'] ['file_upload'] ['tmp_name'])) {'Hata alıyorum:' Undefined index: tmp_name [APP \ Controller \ UploadFilesController.php, satır 23] ' – frantsium

1

bunu tekrar yardımcı Umut bu

if (!empty($this->request->data['UploadFile']['file_upload'])) {    
    foreach($this->request->data['UploadFile']['file_upload'] as $file){ 
     if (is_uploaded_file($file['tmp_name'])) { 
        $fileData = fread(fopen($file['tmp_name'], "r"), $file['size']); 
        $this->request->data['UploadFile']['name'] = $file['name']; 
        $this->request->data['UploadFile']['size'] = $file['size']; 
        $this->request->data['UploadFile']['URL'] = $file['tmp_name']; 
        $this->request->data['UploadFile']['data'] = $fileData; 
        $this->UploadFile->create(); 
        $this->UploadFile->save($this->request->data); 
      } 
    } 
} 

gibi foreach kodunu değiştirmek gerekir, böylece $ this-> request-> veri [ 'DosyaYükle'] [ 'file_upload'] dizisi olduğunu söyledi!

public function uploadFile() { 
    $filename = ''; 
     if ($this->request->is('post')) {   // checks for the post values 
      $uploadData = $this->request->data ['UploadFile']['file_upload']; 
      //print_r($this->request->data); die; 
      foreach($uploadData as $file){ 
       $filename = basename($file['name']); // gets the base name of the uploaded file 
       $uploadFolder = WWW_ROOT. 'files'; // path where the uploaded file has to be saved 
       $filename = $filename; // adding time stamp for the uploaded image for uniqueness 
       $uploadPath = $uploadFolder . DS . $filename; 
       if(!file_exists($uploadFolder)){ 
        mkdir($uploadFolder); // creates folder if not found 
       } 
       if (!move_uploaded_file($file['tmp_name'], $uploadPath)) { 
        return false; 
       } 
       echo "Sa sisestasid faili: $filename<br>"; 

        $this->request->data['UploadFile']['name'] = $file['name']; 
        $this->request->data['UploadFile']['size'] = $file['size']; 
        $this->request->data['UploadFile']['URL'] = $file['tmp_name']; 
        $this->UploadFile->create(); 
        $this->UploadFile->save($this->request->data); 
      }   
     } 
    } 

Konukçumun ve işleyişinin bu çalıştı: Bence

+0

3 aynı uyarıyı aldım,' Uyarı (2): is_uploaded_file() parametre 1'in dize olmasını bekler, dizi verilen [APP \ Controller \ UploadFilesController.php, line 25] ' – frantsium

+0

Burada düzenlenmiş Cevap! –

+0

Veritabanına hiçbir şey alamıyorum – frantsium

İlgili konular