2011-02-03 3 views
-1

FTP 서버가 있지만 PHP 폼에서 업로드 할 명령을 알지 못합니다. WinSCP로 업로드하려면 명령이 필요합니다. 내 코드는 지금까지 다음과 같습니다 : 내가 FTP 서버가 있지만, PHP 양식에서 업로드하는 명령을 모르는FTP로 WinSCP를 사용하여 파일을 업로드 하시겠습니까?

<html> 
<body> 

<?php 


if(isset($_FILES["uploaded"])) 
{ 
print_r($_FILES); 
if(move_uploaded_file($_FILES["uploaded"]["tmp_name"],"<root>/domains/sigaindia.com/public_html/reymend/".$_FILES["uploaded"]["name"])) 
echo "FILE UPLOADED!"; 
} 
else 
{ 
print "<form enctype='multipart/form-data' action='fup1.php' method='POST'>"; 
print "File:<input name='uploaded' type='file'/><input type='submit' value='Upload'/>"; 
print "</form>"; 
} 

?> 

</body> 
</html> 
+1

타자'the' 지나치게 복잡하지입니다 .. –

+0

왜 WinSCP를 사용 하시겠습니까? PHP에는 자체 FTP 기능이 있습니다. http://php.net/manual/en/book.ftp.php –

+0

WinSCP는 어디에서 적합합니까? 포함 된 코드는 HTTP POST 용이며 FTP 및 WinSCP와는 다른 것입니다. – Arvin

답변

1
$host = "ftp.example.com"; 
$user = "anonymous"; 
$pass = ""; 

// You get this from the form, so you don't need to do move_uploaded_file() 
$fname = "/public_html/new_file.txt"; 
$fcont = "content"; 

function ftp_writeFile($ftp, $new_file, $content, $debug=false) { 
    extract((array)pathinfo($new_file)); 

    if ([email protected]_chdir($ftp, $dirname)) { 
     return false; 
    } 

    $temp = tmpfile(); 
    fwrite($temp, $fcont); 
    rewind($temp); 

    $res = @ftp_fput($ftp, $basename, $temp, FTP_BINARY); 
    if ($debug) echo "a- '$new_file'".(($res)?'':" [error]")."<br/>"; 
    fclose($temp); 

    return $res; 
} 

$ftp = ftp_connect($host); 
if (!$ftp) echo "Could not connect to '$host'<br/>"; 

if ($ftp && @ftp_login($ftp, $username, $password)) { 
    ftp_writeFile($ftp, $fname, $fcont, true); 
} else { 
    echo "Unable to login as '$username:".str_repeat('*', strlen($password))."'<br/>"; 
} 

ftp_close($ftp); 

http://au.php.net/manual/en/book.ftp.php

+0

안녕하세요 멋진 아이디어 친구,하지만 wana 그 move_uploaded_file()이 업로드 작업, 내놔 ur 제안을 할 사용 ... –

1

. WinSCP로 업로드하려면 명령이 필요합니다. 지금까지 내 코드는 다음과 같습니다.

PHP와 그 형식보다 HTTP에 대한 이야기가있는 경우 - HTTP는 FTP가 아니며 그 반대도 마찬가지입니다.

WinSCP는 SSH 클라이언트입니다. SSH는 HTTP와는 다른 프로토콜입니다. SSH는 FTP와는 다른 프로토콜입니다. 당신이 당신의 PHP 스크립트는 FTP 서버에 웹 서버에 업로드 된 파일을 전송하려면

, 같은 시도 :

foreach ($_FILES as $f) { 
    if (file_exists($f['tmp_name'])) { 
     $dest = 'ftp://' . $username . ':' . $password . 
       '@' . $ftpserver . $ftp_path; 
     file_put_contents($f['tmp_name'], $dest); 
    } 
} 
+0

헤이 친구, 고마워, ur 내 rescuer 지금 ... ur 코드는 smiply 던져 - probs., 그것은 나를 위해 일한 .. N 내 왕성한 감사 tu 버디 .... –

+0

단지 가치가 WinSCP는 FTP 클라이언트입니다 언급 너무. 그래도 답변의 유효성은 변하지 않습니다. –