Evony Guides and Help
Trik Forum - RuneScape Forum  
Register Forum Homepage Members Mark Forums Read


Trik Members: 34,705 | Total Posts: 134,006 | Total Threads: 25,847
Welcome to our newest member, ahr1mz.
Go Back   Trik Forum - RuneScape Forum > Off-Topic > General Discussion
Reload this Page [PHP] FTP file upload
General Discussion Feel free to talk about anything and everything in here.


Reply
 
Thread Tools Display Modes
[PHP] FTP file upload
Old
  (#1)
Pureblood is Offline
Private Second Class
Pureblood is an unknown quantity at this point
 
Posts: 58
Join Date: May 2008
   
Default [PHP] FTP file upload - 06-03-2008, 06:15 PM

Code:
?php
//by charbsk

// FTP Configuration
$FTP_User = "$username";
$FTP_Pass = "$password";
$FTP_Host = "###";
$FTP_Root = "$dir";

// If the form was submitted
if (isset($action) && $action == "submit")
{
   
    if ($dir == "-1")
    {
        echo "Error: Please choose a File Type to upload";
        exit;
    }

    // Connect to the ftp address
    $Connect = ftp_connect($FTP_Host);

    if (!$Connect)
    {
        echo "Error: Could not connect to ftp server<br>";
        exit;
    }

        echo "Connected to $FTP_Host<br>";

    // Login
    $login = ftp_login($Connect, $FTP_User, $FTP_Pass);

    if (!$login)
    {
        echo "Error: Could not log on as $FTP_User<br>";
        ftp_quit($Connect);
        exit;
    }

    echo "Logged in as $FTP_User<br>";
   
    //Turns passive mode on
    $passive = ftp_pasv ($Connect, true );
   
    /*
    if (!passive){
        echo "Failed to enter passive mode.<br>";
    }
    else {
        echo "Entered passive mode.<br>";
    }*/

    if (ftp_chdir($Connect, "$FTP_Root"))
    {
    echo "Current directory is now: " . ftp_pwd($Connect) . "<br>";
    }
    else echo "Cannot change directory";

    // Set the filename to be uploaded
    $Filename = $_FILES['File_1']['name'];
    $myFile = $_FILES['File_1'];
    $destination_file = $FTP_ROOT.$_FILES['File_1']['name'];

    // Set the local resource (the file that will be uploaded)
    $file = $myFile['tmp_name'];

    $contents = ftp_nlist($Connect, ".");
   
    if (is_array($contents))
    {
        if (in_array("$Filename", $contents))
        {
        echo "The file <font color='red'>$Filename</font> already exists on server<br>";
        ftp_close($Connect);
        exit;
        }
     }
        $upload = ftp_put($Connect, $destination_file, $file, FTP_BINARY);

        if (!$upload)
        {
            // Show success message
            echo "There was a problem uploading $Filename<BR>";
        }
        else
        {
            // Else show error message
            echo "Successfully uploaded $Filename<BR>";
               
        }
           
        $contents = ftp_nlist($Connect, ".");
           
        if (in_array("$Filename", $contents))
        {
                echo "The File $Filename exists<br>";
        }
        else
        {
            echo "The File $Filename does not exist<br>";
        }
   
    ftp_close($Connect);
}

?>
  
Reply With Quote Share with Facebook
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off





======================================================================================== ---------------------------------------------------------------------------------------- ========================================================================================

Your Ad Here

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Copyright © Trik.com