adam291086 Posted August 17, 2008 Share Posted August 17, 2008 I have this function for my FTP client and i am tring to remove the . and .. dir but nothing is happening you can see whats happening here http://www.rubberduckiee.co.uk/admin/FTP/ftp.php function ShowFiles() { $conn = DoConn(); $currDir = ""; // Get the name of the current directory if(isset($_GET["currDir"])) $currDir = $_GET["currDir"]; else $currDir = ftp_pwd($conn); // Retrieve a list of files and directories // and display the appropriate icon for each $fList = @ftp_nlist($conn, $currDir); // We will work out the parent directory $parentDir = strrev($currDir); $parentDir = ereg_replace("^[a-zA-Z0-9\-]*/", "", $parentDir); $parentDir = strrev($parentDir); ?> <img src='parent.gif'> <a href='ftp.php?command=listFiles&currDir=<?php echo $parentDir; ?>'> Back </a> <br> <?php for($i = 0; $i < sizeof($fList); $i++) { // We will remove the parent directory (if any) // from the name of the file that gets displayed $trimFile = ereg_replace("^$currDir", "", $fList[$i]); // Remove any forward slash at front of name $trimFile = ereg_replace("^/", "", $trimFile); if($fList[$i] == '.') $i++; if(@ftp_chdir($conn, $fList[$i])) { @ftp_cdup($conn); ?> <img src='folder.gif'> <a href='ftp.php?command=listFiles&currDir=<?php echo $fList[$i]; ?>'> <?php echo $trimFile; ?> </a> <br> <?php } else { ?> <img src='file.gif'> <a href='ftp.php?command=getFile&currFile=<?php echo $fList[$i]; ?>&currDir=<?php echo $currDir; ?>'> <?php echo $trimFile; ?> </a> <br> <?php } } } Link to comment https://forums.phpfreaks.com/topic/120071-ftp-client/ Share on other sites More sharing options...
JD* Posted August 18, 2008 Share Posted August 18, 2008 Just so I understand correctly...you don't want to display the . and .. links on your top directory, or ever? Link to comment https://forums.phpfreaks.com/topic/120071-ftp-client/#findComment-618841 Share on other sites More sharing options...
chronister Posted August 18, 2008 Share Posted August 18, 2008 incorporate this in the appropriate spot.... <?php if($fList[$i] == '.' || $fList[$i] == '..') // from what I can tell, $fList[$i] is the actual dir listing. { // skip these and move on to the next item } else { // show the links as the current dir is not . or .. } ?> Link to comment https://forums.phpfreaks.com/topic/120071-ftp-client/#findComment-618873 Share on other sites More sharing options...
adam291086 Posted August 18, 2008 Author Share Posted August 18, 2008 i have added in that and the . and .. are still appearing. here is the function function ShowFiles() { $conn = DoConn(); $currDir = ""; // Get the name of the current directory if(isset($_GET["currDir"])) $currDir = $_GET["currDir"]; else $currDir = ftp_pwd($conn); // Retrieve a list of files and directories // and display the appropriate icon for each $fList = @ftp_nlist($conn, $currDir); for($i = 0; $i < sizeof($fList); $i++) { // We will remove the parent directory (if any) // from the name of the file that gets displayed $trimFile = ereg_replace("^$currDir", "", $fList[$i]); // Remove any forward slash at front of name $trimFile = ereg_replace("^/", "", $trimFile); if($fList[$i] == '.' || $fList[$i] == '..') { $i++; } else { if(@ftp_chdir($conn, $fList[$i])) { @ftp_cdup($conn); ?> <img src='folder.gif'> <a href='ftp.php?command=listFiles&currDir=<?php echo $fList[$i]; ?>'> <?php echo $trimFile; ?> </a> <br> <?php } else { ?> <img src='file.gif'> <a href='ftp.php?command=getFile&currFile=<?php echo $fList[$i]; ?>&currDir=<?php echo $currDir; ?>'> <?php echo $trimFile; ?> </a> <br> <?php } } } } Link to comment https://forums.phpfreaks.com/topic/120071-ftp-client/#findComment-619090 Share on other sites More sharing options...
adam291086 Posted August 18, 2008 Author Share Posted August 18, 2008 i have found away around it by setting the for loop to start with 2 therefore missing the first two bits of information out of the array. Is this the best way to go about it? for($i = 2; $i < sizeof($fList); $i++) $fList is the array that contains all the files and folders. it just seems the If statement wasn't working at all Link to comment https://forums.phpfreaks.com/topic/120071-ftp-client/#findComment-619132 Share on other sites More sharing options...
JD* Posted August 18, 2008 Share Posted August 18, 2008 I usually do the reverse of what you have: <?php if($fList[$i] != '.' || $fList[$i] != '..') { if(@ftp_chdir($conn, $fList[$i])) { @ftp_cdup($conn); ?> <img src='folder.gif'> <a href='ftp.php?command=listFiles&currDir=<?php echo $fList[$i]; ?>'> <?php echo $trimFile; ?> </a> <br> <?php } else { ?> <img src='file.gif'> <a href='ftp.php?command=getFile&currFile=<?php echo $fList[$i]; ?>&currDir=<?php echo $currDir; ?>'> <?php echo $trimFile; ?> </a> <br> <?php } } Using the != should skip past them with no problem Link to comment https://forums.phpfreaks.com/topic/120071-ftp-client/#findComment-619199 Share on other sites More sharing options...
adam291086 Posted August 19, 2008 Author Share Posted August 19, 2008 next problem i am having with the downloading of a file. Heres the function function GetFile() { $filename = $_GET['currFile']; $filename = str_replace("/rubberduckiee","",$filename); $filename='www.rubberduckiee.co.uk'.$filename; // required for IE, otherwise Content-disposition is ignored if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); // addition by Jorg Weske $file_extension = strtolower(substr(strrchr($filename,"."),1)); if( $filename == "" ) { echo "<html><title>eLouai's Download Script</title><body>ERROR: download file NOT SPECIFIED. USE force-download.php?file=filepath</body></html>"; exit; } elseif ( ! file_exists( $filename ) ) { echo $filename; echo "<html><title>eLouai's Download Script</title><body>ERROR: File not found.</body></html>"; exit; }; switch( $file_extension ) { case "pdf": $ctype="application/pdf"; break; case "exe": $ctype="application/octet-stream"; break; case "zip": $ctype="application/zip"; break; case "doc": $ctype="application/msword"; break; case "xls": $ctype="application/vnd.ms-excel"; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpeg": case "jpg": $ctype="image/jpg"; break; default: $ctype="application/force-download"; } header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header("Content-Type: $ctype"); // change, added quotes to allow spaces in filenames, by Rajkumar Singh header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); readfile("$filename"); exit(); } someone sent me this code a while ago. I get the error message saying file not found. But if i echo out $file and copy it into the url the file loads? Whats happening. Any help is appreciated Link to comment https://forums.phpfreaks.com/topic/120071-ftp-client/#findComment-619977 Share on other sites More sharing options...
adam291086 Posted August 19, 2008 Author Share Posted August 19, 2008 bump Link to comment https://forums.phpfreaks.com/topic/120071-ftp-client/#findComment-620032 Share on other sites More sharing options...
adam291086 Posted August 19, 2008 Author Share Posted August 19, 2008 sorry but still annoying me Link to comment https://forums.phpfreaks.com/topic/120071-ftp-client/#findComment-620112 Share on other sites More sharing options...
adam291086 Posted August 20, 2008 Author Share Posted August 20, 2008 bump Link to comment https://forums.phpfreaks.com/topic/120071-ftp-client/#findComment-620951 Share on other sites More sharing options...
adam291086 Posted August 20, 2008 Author Share Posted August 20, 2008 right i now have it finding the file but instead of downloading the file all i get it {\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf330 {\fonttbl\f0\fswiss\fcharset0 Helvetica;} {\colortbl;\red255\green255\blue255;} \paperw11900\paperh16840\margl1440\margr1440\vieww9000\viewh8400\viewkind0 \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural \f0\fs24 \cf0 dgdfgdfgdfgg} outputted to the screen . What am i doing wrong Link to comment https://forums.phpfreaks.com/topic/120071-ftp-client/#findComment-620970 Share on other sites More sharing options...
adam291086 Posted August 20, 2008 Author Share Posted August 20, 2008 OK i have got everything working. Secuirty wise i know this isn't a good idea. But i have implemented a check. i check the current directory the user is looking at. If its not where they are supposed to be then they get an error message. I check the curr directory name against a session which is set on loging in. Is this enough to keep it secure? Link to comment https://forums.phpfreaks.com/topic/120071-ftp-client/#findComment-621054 Share on other sites More sharing options...
adam291086 Posted August 20, 2008 Author Share Posted August 20, 2008 is it secure enough or can i implement something else Link to comment https://forums.phpfreaks.com/topic/120071-ftp-client/#findComment-621267 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.