Sam Anderson Sam Anderson - 4 months ago 11x
PHP Question

FTP via PHP Error

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.


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


$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";
} 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

The message I am getting is:

"Connected to, for user upload has

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'];


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

Obviously there's a common apperance amongst this


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:



        $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");


                    echo "The file: '<b>$name</b>' is too big...<br>
                    The size is <b>$size</b> and needs to be less than 100GB. ";
            echo "This type '<b>$type</b>' is not allowed";


This works a treat