2011-12-19 5 views
0

내 파일 업로드 경로가 올바른 폴더에 할당되지 않는 문제가 있습니다. 실제로 업로드되는 파일의 파일 이름에 대한 파일 경로를 수정합니다. 이상한가? 여기에 내가 일하고 있어요 코드 ...업로드 경로를 지정하는 PHP 로봇

여기
<?php 
     $allowed_filetypes = array('.mp4','.gif','.bmp','.png','.html','.psd','.zip','.xml','.css','.js',); 
     $max_filesize = 5904288; 
     $upload_path = 'video'; 

    $filename = $_FILES['userfile']['name']; 
    $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); 

    if(!in_array($ext,$allowed_filetypes)) 
     die('Sorry, cannot take files over blankKB.'); 

    if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize) 
     die('Sorry, cannot take files over blankKB.'); 

    if(!is_writable($upload_path)) 
    die('We are very sorry, a problem is occurring with the CHMOD of this directory'); 

    if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) 
     echo ' Your file was uploaded successfully, view it <a href="file.php?file=' . $filename . '" target="_blank" title="Your File">here</a>'; 
     else 
     echo 'Sorry, but there was an error during the file upload. Please try again.'; 
?> 

파일이 업로드 된 이후의 모습입니다,

videoHello.png는

플러스는 업로드하지 않습니다이다 파일을/video에있는 원하는 디렉토리에 복사합니다.

답변

2

$upload_path . $filename을 쓸 때 실제로 두 개의 문자열을 연결하면 0123이됩니다;

당신이 중 하나를해야 시스템의 디렉토리 분리를 연결할

$upload_path . '/' . $filename 

(유닉스 기반 시스템은 /있어) 또는 문자열로 분리를 구축 $upload_path

$upload_path = 'video/'; 

내 마지막 조언은 사용하는 것입니다하지만 다음과 같은 절대 경로 :

$upload_path = dirname(__FILE__) . '/video/'; 
+0

Techni cally 당신은'DIRECTORY_SEPARATOR'을 사용해야합니다. 그렇지 않으면 +1. :) – deceze

+0

@deceze하지만 너무 못생긴다! ;) – Shad

+0

아, 나는 그런 생각을하지 못했을 것입니다. 고마워요. :) –

관련 문제