[Script] How to Upload files to FTP Using PHP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [Script] How to Upload files to FTP Using PHP

    Hi all,

    It seems amazing seeing PHP managing FTP, below is a script i coded for uploading files to FTP and its fantastic! :D
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Simple FTP Upload Script using PHP by 2netlodge</title>
    </head>
    
    <body>
    <?php
    if(isset($_POST['ftp']))
     	{
    		$ftp = $_POST['ftp'];
    		$username = $_POST['username'];
    		$pwd = $_POST['pwd'];
    		$filename = $_FILES['file']['name'];
    		$tmp = $_FILES['file']['tmp_name'];
    		$d = $_POST['des'];
    		
    		$connect = ftp_connect($ftp)or die("Unable to connect to host");
    		ftp_login($connect,$username,$pwd)or die("Authorization Failed");
    		echo "Connected!<br/>";				
    		
    		if(!$filename)
    			{
    				echo"Please select a file";
    			}
    		else
    			{
    				ftp_put($connect,$d.'/'.$filename,$tmp,FTP_ASCII)or die("Unable to upload");
    						echo"File successfully uploaded to FTP";
    			}
    	}
    ?>
    <form action="" method="post" enctype="multipart/form-data">
    <input type="text" name="ftp" placeholder="FTP link"/><br/>
    <input type="text" name="username" placeholder="Username"/><br/>
    <input type="password" name="pwd" placeholder="Password"/><br/>
    <input type="file" name="file" /><br/>
    <input type="text" name="des" placeholder="Destination"  /><br/>
    <br/><input type="submit" value="Upload"/></form>
    <footer>Share and get more scripts and codes like this, visit <a href="http://2netlodge.com">http://2netlodge.com</a> Forum</footer>
    </body>
    </html>
    Hope it helps!
Working...
X