Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 quick conversion question (asp - php)
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Jezmeister
Senior Member

United Kingdom
1141 Posts

Posted - 06 March 2008 :  18:39:07  Show Profile  Visit Jezmeister's Homepage
I gave php a go since my last topic lol no luck really, but I have no choice but to do this bit in php and I'm stumped... I'll be kind and give two options if you're willing and able to help - read my question and give a better answer or convert my asp code if possible, either would be fantastic as either would solve my problem heh (thanks in advance )

- Question: I'm trying to populate lists of files and folders in a directory, I need two lists, one of files and one of folders as they need to have different options associated with them. with google not giving me an answer and as I know the only filetypes that can be present I figured a php equivalent of a very simple asp solution I thought of would suffice. if however there is a better way of doing this please let me know :) the code currently used to get the file/folders name is simply:
($file = readdir($handle))


Otherwise...
My ASP solution would be simply to strip off any files by means of knowing the possible filetypes there and list the rest as folders, so my check would be... (assume strString to be equiv of $file):
		
strFNameLength = (Len(strString))
strLengthtoRemove1 = (strFNameLength - 4)
strLengthtoRemove2 = (strFNameLength - 5)

strCheck1 = Right(strString,Len(strString)-strLengthtoRemove1)
strCheck2 = Right(strString,Len(strString)-strLengthtoRemove2)

if strCheck1 or strCheck2 = ".htm" or ".html" or ".zip" then
strType = "File"
else
strType = "Folder"
End if



Edited by - Jezmeister on 06 March 2008 18:41:04

phy1729
Average Member

USA
589 Posts

Posted - 06 March 2008 :  19:49:17  Show Profile
This will do what you want

$strFNameLength=strlen($strString);
for($i=$strFNameLength-4;$i<$strFNameLength;++$i) $strCheck1.=$strString[$i];
$strCheck2=$strString[$strFNameLength-5].$strCheck1;

if(($strCheck1=='.htm')||($strCheck1=='.zip')||($strCheck2=='.html')) $strType='File';
else $strType='Folder';

I can't figure out how to keep the logic the same but so far I have

/* no longer necessary
$strFNameLength = strlen($strString);
$strLengthtoRemove1 = ($strFNameLength - 4);
$strLengthtoRemove2 = ($strFNameLength - 5);
*/

$strCheck1 = /*can't figure out how to do this  Right($strString,'4'/*strlen($strString)-$strLengthtoRemove1 works also*/)
$strCheck2 = /*can't figure out how to do this  Right($strString,'5'/*strlen($strString)-$strLengthtoRemove2 works also*/)


Edit:closing tags

Edited by - phy1729 on 06 March 2008 19:50:22
Go to Top of Page

muzishun
Senior Member

United States
1079 Posts

Posted - 06 March 2008 :  21:08:54  Show Profile  Visit muzishun's Homepage
It looks like all you're wanting to do is check the extension, so this should do it. I cut out a couple of the unnecessary parts.

$strCheck1 = substr($strString, -4)
$strCheck2 = substr($strString, -5)

if ($strCheck1 == ".htm" || $strCheck1 == ".html" || $strCheck1 == ".zip" || $strCheck2 == ".htm" || $strCheck2 == ".html" || $strCheck2 == ".zip") {
	$strType = "File";
} else {
	$strType = "Folder";
}

Bill Parrott
Senior Web Programmer, University of Kansas
Co-Owner and Code Monkey, Eternal Second Designs (www.eternalsecond.com)
Personal Website (www.chimericdream.com)
Go to Top of Page

phy1729
Average Member

USA
589 Posts

Posted - 06 March 2008 :  21:41:54  Show Profile
substr that's what I was looking for. Thanks muzishun. BTW: 1 can never return .html and 2 can never return .htm or .zip because of their length.
Go to Top of Page

muzishun
Senior Member

United States
1079 Posts

Posted - 06 March 2008 :  22:15:22  Show Profile  Visit muzishun's Homepage
Good catch. I wasn't really reading the logic behind it, but you're right. Here's what it looks like without the redundant checks:

$strCheck1 = substr($strString, -4);
$strCheck2 = substr($strString, -5);

if ($strCheck1 == ".htm" || $strCheck1 == ".zip" || $strCheck2 == ".html") {
	$strType = "File";
} else {
	$strType = "Folder";
}


Edit: I just noticed I missed a couple semicolons on the one above. They are in red here.

Bill Parrott
Senior Web Programmer, University of Kansas
Co-Owner and Code Monkey, Eternal Second Designs (www.eternalsecond.com)
Personal Website (www.chimericdream.com)

Edited by - muzishun on 06 March 2008 22:16:12
Go to Top of Page

Jezmeister
Senior Member

United Kingdom
1141 Posts

Posted - 07 March 2008 :  05:07:32  Show Profile  Visit Jezmeister's Homepage
thanks guys :) worked perfectly
Go to Top of Page

muzishun
Senior Member

United States
1079 Posts

Posted - 07 March 2008 :  09:23:16  Show Profile  Visit muzishun's Homepage
You're welcome.

Bill Parrott
Senior Web Programmer, University of Kansas
Co-Owner and Code Monkey, Eternal Second Designs (www.eternalsecond.com)
Personal Website (www.chimericdream.com)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.29 seconds. Powered By: Snitz Forums 2000 Version 3.4.07