2013-07-22 3 views
0

파일을 FTP 서버에 업로드하려고합니다. 디렉토리가 chmode 777이어야한다는 if 문에 잡히지 만 ftp의 모든 디렉토리를 수동으로 chmode 77하고 코드에 함수를 추가해야합니다.PHP를 사용하여 FTP로 파일 업로드 - 서버에 쓰지 않습니다.

두 번째로 업로드 프로세스가 시작되면 .tmp 파일이 만들어 지는지 묻습니다. FTP에 업로드 되었습니까? 그렇다면 .mp3 파일과 함께 .tmp 파일에 대한 액세스도 허용해야합니까? 나는 그 과정에서 그들의 사용이 실제로 무엇인지 모르고있어 누군가가 그것을 설명하는 데 시간을 할애하면 도움이 될 것입니다.

몇 가지 변수 내용 : 사전에 어떤 도움

$ftp_server="***********"; 
$ftp_user_name="************"; 
$ftp_user_pass="***********"; 

// set up basic connection 
$conn_id = ftp_connect($ftp_server); 

// login with username and password 
if(ftp_login($conn_id, $ftp_user_name, $ftp_user_pass)){ 

// Configuration - Your Options 
     $allowed_filetypes = array('.mp3','.tmp'); // These will be the types of file that will pass the validation. 
     $max_filesize = 2097152; // Maximum filesize in BYTES (currently 2MB). 

     $cutName = substr($_SESSION['dir'], 0, -1); 

     $upload_path = "htdocs/site/telemessages/en/". $_SESSION['dir']; 
     echo "upload path: ".$upload_path; // The place the files will be uploaded to (currently a 'files' directory). 


    $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename. 

    // Check if the filetype is allowed, if not DIE and inform the user. 
    if(!in_array($ext,$allowed_filetypes)) 
     die('The file you attempted to upload is not allowed.'); 

    // Now check the filesize, if it is too large then DIE and inform the user. 
    if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize) 
     die('The file you attempted to upload is too large.'); 

    // Check if we can upload to the specified path, if not DIE and inform the user. 
    if(!is_writable($upload_path)) 
     die('You cannot upload to the specified directory, please CHMOD it to 777.'); 

    // We'll start handling the upload in the next step 
    echo"FORCE: ".$_FILES['userfile']['tmp_name']; 
     //Upload the file to your specified path. 
    $result = move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename); 


    if(!$result) 
       { 
        return -1; 
       } 
       else 
       { 
        echo $result; 
        //SET PROPER READ PERMISSIONS 

        $result2 = chmod($upload_path, 0777); 
        echo "Result: ".$result2; 
        } 

}else{ 
echo "login failed"; 
} 

감사 : 여기

$upload_path = /htdocs/site2/telemessages/en/Apologies 
$_FILES['userfile']['tmp_name'] = /tmp/phpwkfxrW 

내가 FTP로 파일을 전달하는 데 사용하고 코드입니다.

+1

$ upload_path = "htdocs/site/telemessages/en /". $ _SESSION [ 'dir']; - 이것이 "/"를 선도해야합니까? –

답변

0

언뜻보기에 문제를 일으킬 수있는 몇 가지 사항이 있습니다.

$upload_path = /htdocs/site2/telemessages/en/Apologies 

나는 여러분의 코드에서 실제로 그 주위에 따옴표가 있다고 가정 할 것입니다. 그렇지 않다면 수정해야합니다.

가능성 :

  1. 웹 서버가 해당 디렉토리에 액세스 할 수 없습니다. 일부 서버 팜에서는 여러 서버에서 NFS을 사용하며 이상한 사용 권한이있을 수 있습니다. 서버 회사에 문의하십시오.
  2. /htdocs/site2/telemessages/en/Apologies은 실제로 파일이며 디렉터리가 아니기 때문에 문제가 발생할 수 있습니다.
  3. 위의 Paul Bailey의 설명 : 응용 프로그램 루트 디렉토리와 떨어져 있어야하는 경우 시스템 루트 디렉토리에서 경로를 참조하려고 할 수 있습니다. 따라서 선두에 대한 그의 의견은 /입니다.
관련 문제