2010-07-30 2 views
0

PHP를 사용하여 서버에 파일을 업로드하고 move_uploaded_file 함수가 오류를 반환하지 않는 동안 파일이 대상 폴더에 없습니다. 당신이 볼 수 있듯이 나는 루트로부터 정확한 경로를 사용하고 있으며, 업로드되는 파일들은 최대 크기보다 낮다.내 PHP 이동 파일 스크립트가 실제로 파일을 이동하지 않는 이유는 무엇입니까?

$target = "/data/array1/users/ultimate/public_html/Uploads/2010/"; 
//Write the info to the bioHold xml file. 
$xml = new DOMDocument(); 
$xml->load('bioHold.xml'); 
$xml->formatOutput = true; 
$root = $xml->firstChild; 
$player = $xml->createElement("player"); 
$image = $xml->createElement("image"); 
$image->setAttribute("loc", $target.basename($_FILES['image']['name'])); 
$player->appendChild($image); 
$name = $xml->createElement("name", $_POST['name']); 
$player->appendChild($name); 
$number = $xml->createElement("number", $_POST['number']); 
$player->appendChild($number); 
$ghettoYear = $xml->createElement("ghettoYear", $_POST['ghetto']); 
$player->appendChild($ghettoYear); 
$schoolYear = $xml->createElement("schoolYear", $_POST['school']); 
$player->appendChild($schoolYear); 
$bio = $xml->createElement("bio", $_POST['bio']); 
$player->appendChild($bio); 
$root->appendChild($player); 
$xml->save("bioHold.xml"); 
//Save the image to the server. 
$target = $target.basename($_FILES['image']['name']); 
if(is_uploaded_file($_FILES['image']['tmp_name'])) 
    echo 'It is a file <br />'; 
if(!(move_uploaded_file($_FILES['image']['tmp_name'], $target))) { 
    echo $_FILES['image']['error']."<br />"; 
} 
else { 
    echo $_FILES['image']['error']."<br />"; 
    echo $target; 
} 

도움을 주시면 감사하겠습니다.

에릭 R.는

+0

(내가 $ 대상을 의미 ... 등) –

+0

이 스크립트 폴더에 쓰기 권한이 않습니다 오류를 검사의 적절한 방법은 다음과 같이 간다? – Tim

+0

쓰기 권한이 있으며 오류 출력 0, $ target이 경로와 적절한 파일 이름을 출력합니다. –

답변

0

대부분이 권한 문제입니다.

확인이 $target 디렉토리가 존재하는 경우 :

$target = '/data/etc....'; 
if (!is_dir($target)) { 
    die("Directory $target is not a directory"); 
} 
그래서 여기에 스크립트 내에서 작업을 수행하는 방법, 당신이 직접 물건을 확인하기 위해 직접 쉘 액세스 어떤 종류가없는 가정거야 이 쓰기의 경우

확인 :

if (!is_writable($target)) { 
    die("Directory $target is not writeable"); 
} 

확인 전체 대상 파일 이름이 존재하는 경우/쓰기 가능 - 어쩌면 존재하지만 덮어 쓸 수 없습니다 :

$target = $target . basename($_FILES['image']['name']); 
if (!is_writeable($target)) { 
    die("File $target isn't writeable"); 
} 
그 너머

: 여기 error 매개 변수에서 반향

if(!(move_uploaded_file($_FILES['image']['tmp_name'], $target))) { 
    echo $_FILES['image']['error']."<br />"; 
} 

은 업로드 과정에 순수를 의미, 아무 소용이입니다. 파일을 올바르게 올렸지 만 이동할 수없는 경우에도 여전히 0 (예 : UPLOAD_ERR_OK 상수) 만 표시됩니다. 스크립트에서 나오는 것을

if ($_FILES['images']['error'] === UPLOAD_ERR_OK) { 
    // file was properly uploaded 
    if (!is_uploaded_File(...)) { 
     die("Something done goofed - not uploaded file"); 
    } 
    if (!move_uploaded_file(...)) { 
     echo "Couldn't move file, possible diagnostic information:" 
     print_r(error_get_last()); 
     die(); 

    } 
} else { 
    die("Upload failed with error {$_FILES['images']['error']}"); 
} 
+0

그래서 이것은 옳았습니다. 문제 설명 : "업로드"에 있던 폴더 "2010"이 쓰기 가능하여 모든 수표가 문제없이 통과되었습니다. 그러나 업로드 자체는 쓰기 가능하지 않았습니다. 이 모든 수표를 사용하면 저것에 대해 생각하게되었습니다. 그래서 내가 업로드 할 수있게 만들면 아름답게 작동했습니다. 고마워. 마크. –

1

당신은 페이지를 호스팅하는 누구든 업로드하고 파일을 이동할 수 있도록 구성 설정이 있는지 확인해야합니다. 대부분은 이러한 기능을 비활성화 할 수 있습니다.

전자 메일로 보내고 사용 가능 여부를 묻기 만하면됩니다.

희망이 도움이됩니다.

+0

PS 로컬 시스템에서 스크립트를 테스트 했습니까? –

+0

작년 현재 서버에 업로드 할 수있었습니다. 내가 그들과 함께 확인해 볼 것이다. –

0

is_uploaded_file 및 move_uploaded_file에 대한 호출이 다릅니다. is_uploaded_file의 경우 'name'을 확인하고 'tmp_name'에서 전달할 move_uploaded_file을 확인합니다. 'name'을 (를) 사용하기 위해 move_uploaded_file로 전화를 변경해보십시오.

+0

'move_uploaded_file()'은'tmp_name'에있는 서버 측 임시 이름을 소스로 요구합니다. 'name'으로 변경하는 것은 클라이언트 측 원래 파일 이름이므로 'no such file'과 함께 실패하게됩니다. –

관련 문제