Forum Moderators: coopster

Message Too Old, No Replies

PHP convert from ASP

         

smiddy

6:28 pm on Sep 10, 2004 (gmt 0)

10+ Year Member



I have one web page that needs to be converted from ASP to PHP. Just one. I don't want to spend countless days learning PHP just to do this. It's for my personal home web site.

I wrote the ASP page earlier this year and what it does is page through photos in a directory using two navigation buttons. Works great in ASP. Can it be done in PHP? If I'm barking up the wrong tree or asking too much, that's cool. I thought it would be worth a try to have some PHP genius here convert it for me so I wouldn't have to spend all of my free weekend trying to learn something I'll never use again.

Here's the code from my ASP page...

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<TITLE>slide show</TITLE>
<%
Dim objFSO, objFolder, objPass
Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
Set objFolder=objFSO.GetFolder("C:\WebSite1\Images\Jan04")
objPass = objFolder.Files.Count

Set objFolder = Nothing
Set objFSO = Nothing
%>
<script>
thisImg=1
function newSlide(direction)
{if(document.images)
{thisImg = thisImg + direction
if(thisImg<1)
{thisImg = <%=objPass%>}
if(thisImg > <%=objPass%>)
{thisImg = 1}
document.slider.src="file:///C:/WebSite1/images/Jan04/slide"+thisImg+".jpg"}}
</script>
</head>

<BODY BGCOLOR=WHITE>
<LEFT>
<TABLE BORDER=0 CELLPADDING=0
CELLSPACING=0>
<TR>
<TD VALIGN=BOTTOM>

</TD>
<TD>
<A HREF="javascript:newSlide(-1)">
<IMG height=56 width=35 SRC=file:///C:/WebSite1/graphics/prevbutton.jpg BORDER=0></A>
<IMG height=56 width=57 SRC="graphics/prev.jpg">
<A HREF="javascript:newSlide(1)">
<IMG height=75 width=104 SRC=file:///C:/WebSite1/graphics/nextbutton.jpg BORDER=0></A>
<IMG height=70 width=170 SRC=file:///C:/WebSite1/graphics/slideshowtext.jpg

ALIGN=LEFT><BR CLEAR=ALL>
<IMG SRC=file:///C:/WebSite1/images/Jan04/slide1.jpg NAME="slider">

</TD>
</TR>
</TABLE>
</LEFT>
</BODY>
</HTML>

SkyDog

6:51 pm on Sep 10, 2004 (gmt 0)

10+ Year Member



Is this just returning the file count in your directory:

<?$cnt=count(scandir("C:\WebSite1\Images\Jan04"));?>
You may have to subtract 2 from the above if it counts hidden directories.
Then plug in the value in your javascript:
<?=$cnt;?>

smiddy

2:51 pm on Sep 11, 2004 (gmt 0)

10+ Year Member



I'm not sure about your code there as I don't know PHP. The ASP code is returning a count of the number of files in the directory. That way, when the slide show gets to the last file, it starts over from the beginning rather than showing a dead picture.

How do I replace ASP code with PHP code to do this?

mincklerstraat

7:03 am on Sep 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you're using php4 Skydog's code probably won't help, scandir() is listed as a php5 function. Lemme give this a go, be warned I'm not checking it for accuracy / parse errors etc. I don't know asp really so I'm guessing.

replace:
<%
Dim objFSO, objFolder, objPass
Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
Set objFolder=objFSO.GetFolder("C:\WebSite1\Images\Jan04")
objPass = objFolder.Files.Count

Set objFolder = Nothing
Set objFSO = Nothing
%>
with
<?php
$filearray = array();
$handle = opendir('C:\WebSite1\Images\Jan04');
while($g = readdir($handle)){
if($g <> '.' && $g <> '..') $filearray[] $g;
}
$objpass = count($filearray);
?>

replace:
{thisImg = <%=objPass%>}
if(thisImg > <%=objPass%>)

with:
{thisImg = <?php echo $objpass;?>}
if(thisImg > <?php echo $objpass;?>)

good luck.