ftp_put() 函数不会上传我的文件


ftp_put() function will not upload my file

我已经在谷歌上搜索了这个错误,并从这个网站上找到了很多帖子,但似乎没有任何效果。这是我的来自:

<form enctype="multipart/form-data" action="upload_file.php" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
    Choose a file to upload: <input name="uploadedfile" type="file" /><br />
    <input type="submit" value="Upload File" />
</form>

这是我的PHP代码来自upload_file.php

<?php
$ftp_server = "xxx";
$ftp_username   = "xxx";
$ftp_password   =  "xxx";
$uploadedfile = $_FILES["uploadedfile"]["tmp_name"];
//setup of connection
$conn_id = ftp_connect($ftp_server) or die("could not connect to $ftp_server");
//login
if(@ftp_login($conn_id, $ftp_username, $ftp_password))
{
  echo "conectd as $ftp_username@$ftp_server'n";
}
else
{
  echo "could not connect as $ftp_username'n";
}
ftp_pasv($conn_id, true);
$remote_file_path = "   /home/a9408563/public_html/files".$uploadedfile;
ftp_put($conn_id, $remote_file_path, $uploadedfile,FTP_BINARY);
ftp_close($conn_id);
echo "'n'nconnection closed";
?>

这是我得到的错误:警告:ftp_put() [function.ftp-put]:无法打开该文件:第 18 行的/home/a9408563/public_html/upload_file.php 中没有这样的文件或目录

我不知道下一步该怎么做,任何帮助将不胜感激!

以下是

php.net 对ftp_put的评论的答案:


找到问题,您无法放置目标文件的路径(即使我可以在dos ftp客户端中做到这一点...?

例如 - 这不起作用

ftp_put($conn, '/www/site/file.html','c:/wamp/www/site/file.html',FTP_BINARY);

你必须把

ftp_chdir($conn, '/www/site/');
ftp_put($conn,'file.html', 'c:/wamp/www/site/file.html', FTP_BINARY );

http://php.net/manual/en/function.ftp-put.php

<?php
    if(isset($_POST["submit"])){
// set up basic connection
$conn_id = ftp_connect("xxx"); 
$ftp_user_name="xxx";
$ftp_user_pass="xxx";
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 
$destination_file =  $destination_file = "public_html/api/".$_FILES['uploadedfile']['name'];
$source_file = $_FILES['uploadedfile']['tmp_name']; 
// 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, $destination_file, $source_file, FTP_BINARY); 
// check upload status
if (!$upload) { 
    echo "FTP upload has failed!";
} else {
    echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream 
ftp_close($conn_id); 
    }
?>
<html><body><form action="upload.php" enctype="multipart/form-data" method="post">
<input name="uploadedfile" type="file" />
<input name="submit" type="submit" value="Upload File" />
</form></body></html>

api is my target folder