简体   繁体   English

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

[英]File upload code gives this error - Warning: ftp_put(): Filename cannot be empty

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". 我正在尝试编写允许我将图像上传到ftp服务器的代码,但是由于某种原因,它会引发错误“警告:ftp_put():文件名不能为空”。 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);
}

Sorry everyone, it was a rookie mistake. 抱歉,这是菜鸟的错误。 It's supposed to be $_FILES['headliner-logo']['tmp_name'] not $_FILES['headliner-logo']['tmp-name']! 应该是$ _FILES ['headliner-logo'] ['tmp_name']而不是$ _FILES ['headliner-logo'] ['tmp-name']!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM