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

时间:2015-01-29 10:23:00

标签: php ftp

我已经在google上搜索了这个错误,发现了很多来自这个网站的帖子,但似乎没什么用。 这是我的来自:

<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>

这是我的上传文件来自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中没有此类文件或目录

我不知道接下来该做什么,任何帮助都会非常感激!

1 个答案:

答案 0 :(得分:0)

这是php.net对ftp_put的评论的回答:


发现概率,您无法将路径放到目标文件中 (尽管我可以在dos ftp客户端中执行此操作...?)

e.g。 - 这不起作用

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

相关问题