2012-10-18 5 views
-1

안녕하세요 저는 사이트 구현에 프레임 워크 cakephp를 사용하고 있습니다. 내 현재 PHP 스크립트에서이 오류가 나타납니다 : 정의되지 않은 오프셋 : 1 및 해당 이미 내게 두통을 제공합니다. 내가 잘못하고있는 것을 도와 줄 수 있니?cakephp에서 정의되지 않은 오프셋 : 1

내 코드는 여기에 있습니다 :

function file_upload($file_array, $id){ 
    if(count($file_array)) 
    { 
     $location = "files/library-files/"; 

     foreach ($file_array as $file) { 
      $ext = explode(".", $file['name']); 
      $new_name = md5(uniqid()); 
      $target_path = $location . $new_name .".".$ext[1]; 
      if(move_uploaded_file($file['tmp_name'], $target_path)) 
      { 
       $this->LibraryFiles->create(); 
       $this->LibraryFiles->set('id', $new_name); 
       $this->LibraryFiles->set('library_id', $id); 
       $this->LibraryFiles->set('name', $file['name']); 
       $this->LibraryFiles->set('ext', $ext[1]); 
       $this->LibraryFiles->set('type', $file['type']); 
       $this->LibraryFiles->set('size', $file['size']); 
       if($this->LibraryFiles->save()) 
       { 

       } 
       else 
       { 

       } 
      } 
     } 
    } 
} 
+0

는 파일 배열에 파일이 안의 점, 또는 상위 디렉토리에 대한 포인터하지 않고 있습니까? –

+0

이 줄은 $ target_path = $ location입니다. $ new_name. "."$ ext [1]; 그것은 저에게 오류를주고있었습니다. 수 시간의 연구로 나는 (isset ($ target_path)) $ target_path = $ location이라면 이것을 \t \t \t \t \t 으로 바 꾸었습니다. $ new_name. "."$ ext [1]; else $ target_path = ''; 이제는 더 이상 오류가 없습니다 : D – electricfeel1979

답변

-1

. $ new_name. "."$ ext [1];

if (isset($target_path)) 
$target_path = $location . $new_name .".".$ext[1]; 
else 
$target_path = ''; 

지금과

나는 행복합니다 : D

2

는 다음과 같은 검사를 추가 할 수 있습니다 : 난 그냥이 $ target_path = $ 위치를 대체

if(isset($ext[1])) 
{ 
    $target_path = $location . $new_name .".".$ext[1]; 
} 
else if($file['name'] !== '.' && $file['name'] !== '..') 
{ 
    $target_path = $location . $new_name; 
} 
else 
{ 
    continue; 
} 
관련 문제