OwenMelbz
-
Content Count
2 -
Joined
-
Last visited
Posts posted by OwenMelbz
-
-
Right Im new here and stuggling with a problem im having.I've currently got a Login Script to login to a external ftp and it displays the folders contents, however i need it so it echos a specific file (coursedata.cfg) into a formarea which you can then edit the file and when u click save it overwrites the file with the new one.Im really quiet getting annoyed with it xD as everything i do ends up trying to include the file from the webserver the script is hosted on and not the external ftp source.thanksFull Code Bellow
<html><head><title>Simple FTP Manager</title><style>body {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: small;color: black;}a {color: #666666;text-decoration: underline;}a:hover {text-decoration: none;}</style></head><body><?php/*Simple FTP ManagerProgrammed by Federico Ram?rez ( fedekiller )Copyright 2006All Rights ReservedNOTE: You must upload the file temp.txt in the same directory than this file, and CHMOD it to 777*/$host = '';$port = 21;$timeout = 10;$user = '';$pass = '';$secure = false; // If OpenSSL support is not active, this wont work, so change it to falsefunction clean ( ){foreach ( $_REQUEST as $key => $val ){$_REQUEST [ $key ] = stripslashes ( strip_tags ( htmlspecialchars ( $val, ENT_QUOTES ) ) ) ;$$key = stripslashes ( strip_tags ( htmlspecialchars ( $val, ENT_QUOTES ) ) ) ;}}clean ( ) ;if ( $secure ){$con = ftp_ssl_connect ( $host, $port, $timeout ) ;}else{$con = ftp_connect ( $host, $port, $timeout ) ;}if ( !$con ){echo 'Could not connect to that host.';}if ( !file_exists ( 'temp.txt' ) || !is_writable ( 'temp.txt' ) ) // Checks if the temp file is there{die ( 'The temp file does not exists or is not writable' ) ;}if ( @ftp_login ( $con, $user, $pass ) ){if ( isset ( $_GET [ 'delete' ] ) ){if ( isset ( $_GET [ 'fd' ] ) ){ftp_delete ( $con, $_GET [ 'fd' ] .'/'.$_GET [ 'delete' ] ) ;}elseif ( isset ( $_GET [ 'subfd' ] ) ){ftp_delete ( $con, $_GET [ 'fd' ] .'/'.$_GET [ 'subfd' ] .'/'.$_GET [ 'delete' ] ) ;}else{ftp_delete ( $con, $_GET [ 'delete' ] ) ;}}elseif ( isset ( $_GET [ 'download' ] ) ){if ( isset ( $_GET [ 'fd' ] ) ){ftp_get ( $con, 'temp.txt', $_GET [ 'fd' ] .'/'.$_GET [ 'download' ] , FTP_BINARY ) ;}elseif ( isset ( $_GET [ 'subfd' ] ) ){ftp_get ( $con, 'temp.txt', $_GET [ 'fd' ] .'/'.$_GET [ 'subfd' ] .'/'.$_GET [ 'download' ] , FTP_BINARY ) ;}else{ftp_get ( $con, 'temp.txt', $_GET [ 'download' ] , FTP_BINARY ) ;}header ( 'Content-Disposition: attachment; filename=temp.txt' ) ; // To force the downloadreadfile ( 'temp.txt' ) ;$fp = fopen ( 'temp.txt', 'w' ) ;fwrite ( $fp, '', filesize ( 'temp.txt' ) ) ; // After we write the data in the temp file we clean itfclose ( $fp ) ;}elseif ( isset ( $_GET [ 'upload' ] ) ){if ( $_POST [ 'Submit' ] ){$file = $_FILES [ 'file' ] [ 'tmp_name' ] ;$name = $_FILES [ 'file' ] [ 'name' ] ;$path = $_POST [ 'path' ] ;$upload = ftp_nb_put ( $con, $path.'/'.$name, $file, FTP_BINARY ) ;while ( $upload == FTP_MOREDATA ){echo ".";$ret = ftp_nb_continue ( $con ) ;}if ( $upload != FTP_FINISHED ){die ( 'There has been an error uploading the file' ) ;}echo 'File uploaded!';}else{if ( isset ( $_GET [ 'subfd' ] ) ){$path = $_GET [ 'fd' ] .'/'.$_GET [ 'subfd' ] ;}elseif ( isset ( $_GET [ 'fd' ] ) ){$path = $_GET [ 'fd' ] ;}else{$path = '.';}echo '<form action="?upload" method="post" enctype="multipart/form-data"><table border="0"><tr><td>Upload a file </td><td><input type="file" name="file" /></td></tr><tr><td> </td><td><input type="hidden" name="path" value="'.$path.'" /><input type="submit" name="Submit" value="Upload!" /></td></tr></table></form>';}}else{$fd = $_GET [ 'fd' ] ;$subfd = $_GET [ 'subfd' ] ;if ( empty ( $fd ) ){$contents = ftp_nlist ( $con, '.' ) ;echo '<h1>File List: ( '.ftp_pwd ( $con ) .' ) </h1>';echo '<a href="?upload">Upload File</a><br />';echo 'Go UP<br /><br />';}elseif ( isset ( $_GET [ 'subfd' ] ) ){$contents = ftp_nlist ( $con, $fd.'/'.$subfd ) ;echo '<h1>File List: ( '.ftp_pwd ( $con ) .$fd.'/'.$subfd.'/ ) </h1>';echo '<a href="?upload&fd='.$_GET [ 'fd' ] .'&subfd='.$_GET [ 'subfd' ] .'">Upload File</a><br />';echo '<a href="?upload&fd='.$_GET [ 'fd' ] .'">Go UP</a><br /><br />';}else{$contents = ftp_nlist ( $con, $fd ) ;echo '<h1>File List: ( '.ftp_pwd ( $con ) .$fd.'/ ) </h1>';echo '<a href="?upload&fd='.$_GET [ 'fd' ] .'">Upload File</a><br />';echo '<a href="'.$_SERVER [ 'PHP_SELF' ] .'">Go UP</a><br /><br />';}$files = array ( ) ;$folders = array ( ) ;foreach ( $contents as $c ){if ( eregi ( '.', $c ) ){$files [ ] = $c;}else{$folders [ ] = $c;}}echo '<strong>Folders:</strong><br />';foreach ( $folders as $f ){if ( !empty ( $fd ) ){echo '<a href="'.$_SERVER [ 'PHP_SELF' ] .'?fd='.$fd.'&subfd='.$f.'">/'.$f.'</a><br />';}else{echo '<a href="?fd='.$f.'">/'.$f.'</a><br />';}}echo '<br /><strong>Files:</strong><br />';foreach ( $files as $f ){echo $f.' - <a href="?delete='.$f.'">Delete</a> - <a href="?download='.$f.'">Download</a><br />';//echo '<textarea name="theText" cols="150" rows="20">';include "server.cfg";//echo "</textarea>";}}echo '<div align="right">'.$host.' is powered by '.ftp_systype ( $con ) .'</div>';}else{echo 'Sorry, username and password combination does not exists';}?></body></html>
Edit .txt File In Ftp Via Webpage file on external ftp
in Programming
Posted · Report reply
yh but wanted a bit more than that.I've actually finished the code now and is shown below