doudaiyao0934 2016-05-24 11:54
浏览 49
已采纳

FTP错误

I am having an issue with uploading to FTP from my website through PHP.

It connects OK, but then has an issue with the uploading of the image.

HTML

<form action="../scripts/php/saveupload.php" method="post">
    <input name="file" type="file" />
    <input name="submit" type="submit" value="Upload File" />
</form>

PHP

$ftp_server = "XXXXXX";
$ftp_user_name = "XXXXX";
$ftp_user_pass = "XXXXX";
$destination_file = "/public_html/img/news/";
$source_file = $_FILE['file']['tmp_name'];

// set up basic connection
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, true); 

// 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, $destination_file, $source_file); 

// 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);

The message I am getting is:

"Connected to ftp.theucl.co.uk, for user theucl.co.ukFTP upload has failed!"

This is now the error I am getting after following Niths advice on the error...

It appears the error is around the following..

$source_file = $_FILES['file']['tmp_name'];

and

$upload = ftp_put($conn_id, $destination_file.$_FILES['file']['tmp_name'], $source_file,FTP_ASCII);

Obviously there's a common apperance amongst this

  • 写回答

2条回答 默认 最新

  • doute3621 2016-05-29 17:46
    关注

    Solved it by using a tutorial on Youtube by Thorn Web... instead of altering what I had above I restarted it and now have the following:

    <?php
    
        if($_POST['submit']){
    
            $name = $_FILES['upload']['name'];
            $temp = $_FILES['upload']['tmp_name'];
            $type = $_FILES['upload']['type'];
            $size = $_FILES['upload']['size'];
    
            if(($type == "image/jpeg") || ($type == "image/jpg") || ($type == "image/gif")){
    
                    if($size <= 1000000){
    
                        move_uploaded_file($temp, "../img/news/$name");
    
    
                    }else{
    
                        echo "The file: '<b>$name</b>' is too big...<br>
                        The size is <b>$size</b> and needs to be less than 100GB. ";
                    }       
            }else{
                echo "This type '<b>$type</b>' is not allowed";
            }
        }
    
    ?>
    

    This works a treat

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能