【问题标题】:ftp_put() function will not upload my fileftp_put() 函数不会上传我的文件
【发布时间】:2015-01-29 10:22:59
【问题描述】:

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

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

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


    【解决方案1】:

    下面是 ftp_put 上 php.net 的 cmets 的回答:


    找到了问题,你不能把路径放到目标文件 (即使我可以在 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

    【讨论】:

    • 所以我把它改成了:ftp_chdir($conn_id, '/home/a9408563/public_html/files/'); ftp_put($conn_id, $uploadedfile, "/home/a9408563/public_html/files".$uploadedfile, FTP_BINARY);但它仍然无法正常工作
    【解决方案2】:
    <?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
    

    【讨论】:

      猜你喜欢
      • 2013-12-22
      • 2019-01-07
      • 1970-01-01
      • 2023-03-08
      • 2013-03-30
      • 2019-03-04
      • 2015-09-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多