PHP를 사용하여 FTP 파일 업 로더를 마무리하는 데 문제가 있습니다. 나는 여기에서 찾아낸 php.net에서 예제를 사용하고있다 : http://php.net/manual/en/ftp.examples-basic.php 그리고 약간 코드를 수정했다.PHP FTP 업로드 오류 : 경고 : ftp_put() [function.ftp-put] : 파일 이름을 비워 둘 수 없습니다.
<?php
//Start session();
session_start();
// Checking the users logged in
require_once('config.php');
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
$ftp_server="*";
$ftp_user_name="*";
$ftp_user_pass="*";
$paths="members/userUploads";
$name=$_FILES['userfile']['name'];
$source_file=$_FILES['userfile']['tmp_name'];
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
// upload the file
$upload = ftp_put($conn_id, $paths.'/'.$name, $source_file, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
$CurrentUser = $_SESSION['CurrentUser'];
$qry = "SELECT * FROM members WHERE username='$CurrentUser'";
$result = mysql_query($qry);
$result = mysql_fetch_array($result);
$CurrentUser = $result[memberID];
$qry = "INSERT into uploads (UploadPath, UploadUser) VALUES('$file_name', '$CurrentUser')";
echo "Uploaded $source_file to $ftp_server as $paths.'/'.$name";
}
// close the FTP stream
ftp_close($conn_id);
?>
그러나 코드가 일부 파일이 아닌 다른 사람을 위해 작동합니다. 그것이 작동하지 않는 경우 그 오류를 제공합니다
에러가 발생했을 경우 파일을 보낼 때name
가 설정되지 않을 수 있습니다
Warning: ftp_put() [function.ftp-put]: Filename cannot be empty in ... on line 48.
어떤 파일이 작동하지 않습니까? '$ _FILES [ 'userfile'] [ 'name']','$ _FILES [ 'userfile'] [ 'tmp_name']'항상 값을 가지고 있는지 확인하십시오. – pankar