0

I have a form on my page that allows me to add new articles.There are two fields for photo upload (thumbnail and main photo) unfortunately I have a problem with uploading photos on FTP.

I get the error: ftp_put (): This is a private system - No anonymous login [file]

$thumbnail_img = $_FILES['a_thumbnail']['name'];
$temp_name1 = $_FILES['a_thumbnail']['tmp_name'];

$thumbnail_img = $_FILES['a_image']['name'];
$temp_name2 = $_FILES['a_image']['tmp_name'];

move_uploaded_file($temp_name1,"a_thumbnails/$thumbnail_img");
move_uploaded_file($temp_name2,"a_images/$thumbnail_img");


$destination_file1 = "/www/a_thumbnails/";
$destination_file2 = "/www/a_images/";


// set up basic connection
$conn_id = ftp_connect($ftgt_ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftgt_user_name, $ftgt_user_pass);

ftp_pasv($conn_id, true);

// upload the file
$upload1 = ftp_put($conn_id, $destination_file1, $temp_name1, FTP_BINARY);
$upload2 = ftp_put($conn_id, $destination_file2, $temp_name2, FTP_BINARY);

ftp_close($conn_id);

form:

<form method="post" class="form-horizontal" enctype="multipart/form-data" action="upload.php">
    <div class = row>
        <div class="col-6">
            <div class="form-group" style="padding-left: 50px; text-align: left">
                <label>Thumbnail</label>
                <input name="a_thumbnail" type="file" class="form-control" style="margin-left: -25px;!important; border: none" required>
            </div>
        </div>
        <div class="col-6">
            <div class="form-group" style="padding-left: 50px; text-align: left">
                <label>Photo</label>
                <input name="a_image" type="file" class="form-control" style="margin-left: -25px;!important; border: none"  required>
            </div>
        </div>
    </div>
    <div class="col-12">
        <div class="form-group">
            <input name="submit" value="SAVE" type="submit" style="width: 95%;"  class="btn btn-primary form-control">
        </div>
    </div>
</form>

0

1 Answer 1

1

The message stated that your FTP server requires user login. So you must have a proper ftp_login() on the connection before putting files there. And your login information is probably incorrect.

Try to test the login result before proceeding to upload. Like this:


$thumbnail_img = $_FILES['a_thumbnail']['name'];
$temp_name1 = $_FILES['a_thumbnail']['tmp_name'];

$thumbnail_img = $_FILES['a_image']['name'];
$temp_name2 = $_FILES['a_image']['tmp_name'];

move_uploaded_file($temp_name1,"a_thumbnails/$thumbnail_img");
move_uploaded_file($temp_name2,"a_images/$thumbnail_img");


$destination_file1 = "/www/a_thumbnails/";
$destination_file2 = "/www/a_images/";


// set up basic connection
$conn_id = ftp_connect($ftgt_ftp_server);

// login with username and password
if (!ftp_login($conn_id, $ftgt_user_name, $ftgt_user_pass)) {
    // You'd probably want better error handling here
    exit('FTP Login Failed');
}

ftp_pasv($conn_id, true);

// upload the file
$upload1 = ftp_put($conn_id, $destination_file1, $temp_name1, FTP_BINARY);
$upload2 = ftp_put($conn_id, $destination_file2, $temp_name2, FTP_BINARY);

ftp_close($conn_id);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.