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

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?