dtzjvj3915 2014-08-22 15:49
浏览 99

文件上传代码给出了此错误 - 警告:ftp_put():文件名不能为空

I'm trying to write code that will allow me to upload an image to the ftp server, but for some reason it throws the error "Warning: ftp_put(): Filename cannot be empty". I've looked around and and none of the solutions I found work, please help!

Here is my form code:

<form id="edit-cd" method="post" enctype="multipart/form-data">
    <input type="file" name="headliner-logo" />
    <input type="submit" name="submit-headlogo" class="submit-btn" value="Submit" />
</form>
<?php
if (isset($_POST['submit-headlogo'])) {
    if ($_FILES['headliner-logo']['size'] <= 0) {
        error("No file was chosen to upload");
    } else if ($_FILES['headliner-logo']['size'] > 1572864) {
        error("File too large, max. filesize is 1.5mb");
    } else if ($_FILES['headliner-logo']['type'] != "image/png") {
        error("Invalid filetype, .png only");
    } else {
        setHeadlinerLogo($_FILES['headliner-logo']['tmp-name'], $_FILES['headliner-logo']['name']);
    }
}
?>

And here is the code that does the uploading:

function setHeadlinerLogo($source, $name) {
    $server = "ftp.server.com";
    $user = "username";
    $pass = "password";
    $dest = "/public_html/directory/img/";

    // Set up connection
    $conn = ftp_connect($server);
    if ($conn) {
        // Login
        $login = ftp_login($conn, $user, $pass);
        if($login) {
            // Upload File
            $upload = ftp_put($conn, $dest.$name, $source, FTP_ASCII);
            if ($upload) {
                success("File successfully uploaded");
            } else {
                error("Something went wrong, contact the admin");
            }
        } else {
        error("Could not log in to server");
        }
    } else {
        error("Could not connect to file server");
    }

    ftp_close($conn);
}
  • 写回答

1条回答 默认 最新

  • doq13207 2014-08-22 20:13
    关注

    Sorry everyone, it was a rookie mistake. It's supposed to be $_FILES['headliner-logo']['tmp_name'] not $_FILES['headliner-logo']['tmp-name']!

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入