-
Posts
307 -
Joined
-
Last visited
Everything posted by TapeGun007
-
No, I didn't know anything about that. I came from ASP (classic), and just trying to get up to speed on something newer (and cheaper). I'll look into that! thanks.
-
Ah ok, I see where I made a mistake in my little example. I was referring to a 2nd function actually being inside another function is what I keep finding as an example... like this: I mean literally "inside" another function. The reason why I'm writing these functions is because I'm making the same calls over and over again within a framework of code. Based upon certain conditions, there are slight variations. Let me show you my incorrect code first. // Define the array first outside the function to make it global. $All_Files = array(); $Temp_Files = array(); $y=0; // This function determines which files are to be displayed. function Add_Files($file, $path, $y){ global $All_Files; $y++; if(file_exists($path.$file)){ $File_Size=filesize($path.$file); } Else{ Echo "File doesn't exists, please contact the Administrator, $path, $file<p>"; } $File_Size=$File_Size/1048576; $temp_size=number_format($File_Size,2); $Total_File_Size = $Total_File_Size + $File_Size; $All_Files[$y]=$file."|".$temp_size." MB's"; } function ListFiles($path, $filetype) { global $All_Files; global $y, $file, $path; if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { /* Weed out the . and .. for going up one directory, so this keeps those from showing */ if ( $file != '.' && $file != '..' ) { // Eventually, I will put a Switch statement here for various conditions Add_Files($file, $path, $y); } } } closedir($handle); natcasesort($All_Files); Originally, I wrote this page with the same code over and over. Then I just wanted to learn how to do functions, so here I am. The code simply looks at all the files in a directory, stores the filename in a string, stores the filesize in another strings and combines the two. Then it stores that one string into an array. I do this because I can't sort a multi-dimensional array properly. The code works fine without being all diced up into functions. I'm just trying to stream line and learn more php. The rest of the code just pulls up the array, splits the filename from the filesize, and displays the links. $counter=1; echo "<table border='0'>"; echo "<tr>"; echo "<td bgcolor='#333333' colspan='2' class='ContentWhite' align='center'> Controls </td><td bgcolor='#333333' class='ContentWhite' align='center' width='300'> File Name </td><td bgcolor='#333333' class='ContentWhite' align='center'> File Size </td>"; foreach ($All_Files as &$Value){ $counter++; echo "<tr>"; // Get the position that the "|" exists in the string. $str_pos=strrpos($Value,"|"); $str_len=strlen($Value); $bgcolor = ($counter % 2)?"#ffffff":"#d9ece7"; ?> <td nowrap bgcolor="<? echo $bgcolor ?>"><a href="download_file.php?file=<? echo substr($Value,0,$str_pos) ?>">[ Download ]</a></td> <td bgcolor="<? echo $bgcolor ?>"><a href="Music_Library/<? echo substr($Value,0,$str_pos) ?>">[ Open ]</a></td> <td bgcolor="<? echo $bgcolor ?>"><? echo substr($Value,0,$str_pos)?></td> <td nowrap align="right" bgcolor="<? echo $bgcolor ?>"><? echo substr($Value,$str_pos+1,strlen($Value)) ?></td> <?php } echo "</table>"; include("components/footer.php"); ?> Originally, I wrote this as ONE function only, and I was able to pass the globals without issue. Now I'm over my head trying to pass information from one function to another and could use some help. $file, $path, and $y. Thank you.
-
After reading much on my searches in Google, I understand that you can call a function within a function. But the one thing I can't seem to find is, can I call a function within a function? Is there a sample code somewhere that I can look at and follow? Example: Function One(); { } Function Two(); { One(); }
-
Anyone else have some suggestions as to why my sorting isn't working properly as Ken suggested?
-
Ken, I did the same test you just did. hehe... yes, and it sorts correctly then. Here is the entire code. Now, don't be too hard on me, I'm new to PHP and am converting from classic ASP. Keep in mind this code is set up for either a filename search OR if they click on a letter. <?php include("components/header.php"); ?> <h1>Search</h1> Currently, this search will list all files that start with a capital letter alphabetically first. Then it will list all files that do not start with a capital letter alphabetically.<p> <form action="download_search.php?type=search" method="post"> <table cellpadding="3" cellspacing="3" border="0"> <tr> <td colspan="2"> <a href="download_search.php?letter=a">A</a>- <a href="download_search.php?letter=b">B</a>- <a href="download_search.php?letter=c">C</a>- <a href="download_search.php?letter=d">D</a>- <a href="download_search.php?letter=e">E</a>- <a href="download_search.php?letter=f">F</a>- <a href="download_search.php?letter=g">G</a>- <a href="download_search.php?letter=h">H</a>- <a href="download_search.php?letter=i">I</a>- <a href="download_search.php?letter=j">J</a>- <a href="download_search.php?letter=k">K</a>- <a href="download_search.php?letter=l">L</a>- <a href="download_search.php?letter=m">M</a>- <a href="download_search.php?letter=n">N</a>- <a href="download_search.php?letter=o">O</a>- <a href="download_search.php?letter=p">P</a>- <a href="download_search.php?letter=q">Q</a>- <a href="download_search.php?letter=r">R</a>- <a href="download_search.php?letter=s">S</a>- <a href="download_search.php?letter=t">T</a>- <a href="download_search.php?letter=u">U</a>- <a href="download_search.php?letter=v">V</a>- <a href="download_search.php?letter=w">W</a>- <a href="download_search.php?letter=x">X</a>- <a href="download_search.php?letter=y">Y</a>- <a href="download_search.php?letter=z">Z</a> </td> </tr> <tr> <td><input name="searchresults" type="text" class="input" /> <input value="Submit" type="submit" /></td> </tr> </table> <p> </form> <?php $selection = $_GET['letter']; if (isset($_POST['searchresults'])){ $str = $_POST['searchresults']; } if ($handle = opendir('Music_Library')) { $y==0; /* Read the files in the directory, then store it in an array to sort it alphabetically */ $All_Files = array(); while (false !== ($file = readdir($handle))) { /* Weed out the . and .. for going up one directory, so this keeps those from showing */ if ( $file != '.' && $file != '..' ) { // Compare the first letter of the filename to the letter that was selected. $compare=substr("$file",0,1); if (strtoupper($selection)==strtoupper($compare)){ $y++; $File_Size=filesize('Music_Library/'.$file); $File_Size=$File_Size/1048576; $Total_File_Size = $Total_File_Size + $File_Size; $All_Files[$y]['FileName']=$file; $All_Files[$y]['FileSize']=number_format($File_Size,2)." MB"; } /* Check the if the string is populated, then set $match */ if (isset($str)){ $match = strpos($file,$str); }/* Set to false or it will run anyway */ else{ $match=false; } if ($match===false){} else { $y++; $File_Size=filesize('Music_Library/'.$file); $File_Size=$File_Size/1048576; $Total_File_Size = $Total_File_Size + $File_Size; $All_Files[$y]['FileName']=$file; $All_Files[$y]['FileSize']=number_format($File_Size,2)." MB"; } } } closedir($handle); // Sort the array natcasesort($All_Files); $counter==1; echo "<table border='0'>"; echo "<tr>"; echo "<td bgcolor='#333333' colspan='2' class='ContentWhite' align='center'> Controls </td><td bgcolor='#333333' class='ContentWhite' align='center' width='300'> File Name </td><td bgcolor='#333333' class='ContentWhite' align='center'> File Size </td>"; foreach ($All_Files as $tempone) { echo "<tr>"; $counter++; $bgcolor = ($counter % 2)?"#ffffff":"#d9ece7"; foreach ($tempone as $key=>$temptwo) { If ($temptwo !== end($tempone)){ /* Display the filename */ echo "<td bgcolor='".$bgcolor."'> <a href=\"download_file.php?file=$temptwo\">[ Download ]</a> </td>"; echo "<td bgcolor='".$bgcolor."'> <a href=\"http://www.sanjosechoir.com/Music_Library/".$temptwo."\" target='_new'>[ Open ]</a> </td>"; echo "<td bgcolor='".$bgcolor."'> $temptwo </td>"; } else { /* Display the size of the file */ echo "<td bgcolor='".$bgcolor."' align='right'> ".$temptwo." </td>"; } } echo "</tr>"; } echo "<tr><td colspan='3' align='right'><b>Total File Size:</b></td><td align='right'><b>".number_format($Total_File_Size,2)." MB</b></td></tr>"; echo "</table>"; } ?> <?php include("components/footer.php"); ?> On my last server, I didn't have to worry about doing anything but changing the case and doing the sort.
-
Since I can't see an example of what you mean, can you not just do that in the flash code itself?
-
sort ($All_Files); That's all I was using. The sort you are suggesting sorts the B's like this which is still not alphabetical: [ Download ] [ Open ] Breathe On Me60bpm.acd-bak.mp3 11.46 MB [ Download ] [ Open ] bounce.mp3 2.72 MB [ Download ] [ Open ] Blessed Be Your Name.mp3 5.97 MB [ Download ] [ Open ] blessthelordloop80.mp3 14.26 MB [ Download ] [ Open ] Bound (G).pdf 0.08 MB
-
Here is an example of what I did on one of my webpages... very simple code. $counter++; if ($counter % 2) { $bgcolor="#ffffff"; } else { $bgcolor="#d9ece7"; } echo "<td bgcolor='".$bgcolor."'>Test</td>" It alternates every other row with white or light blue. Try it.
-
Ok, I've got an issue, and I'm having a really hard time solving this one. Attached is a picture, so you can see what this page does, it will explain a lot: The Project: The user can click on a letter, and all songs that start with that letter will appear. In this first example the user has clicked on the letter "B". Pretend the "[Download]" option in the picture doesn't work (it's no concern at the moment), but the [Open] does work. If a user clicks on [Open] the file will stream and open. The output is all the songs that start with the letter "b" or "B". I use this line of code to compare the strings: if (strtoupper($selection)==strtoupper($compare)){ This way it lists all files regardless of whether or not it starts with an uppercase or lowercase letter. Problem #1: As you can see in the example, it lists all files that start with a Capital "B" alphabetically and then starts over and lists all the files starting with a lowercase "b" alphabetically. Problem #2: If I convert all the filenames to uppercase, then the [Open] link no longer works, because the server is case sensitive so the filename has to be exactly as it is in the directory. So, if I converted "baby girl.mp3" to "BABY GIRL.MP3" so all the files would sort, then the open option will no longer work. Is there some simple way to get around this? Once I get past this issue, then that might solve my search box issues as well. [attachment deleted by admin]
-
Filesize error - worked in php 4.2, not 5.1
TapeGun007 replied to TapeGun007's topic in PHP Coding Help
PFMaBiSmAd, I think you are right. After reviewing code previous... I convert all the filenames to lowercase because when a user searches for a filename, it converts their input to lowercase and compares so it's easier to find a filename. I'm assuming that converting the filename to lowercase is why it cannot find the file. For whatever reason, this worked fine in php 4.2. Edit: After testing that theory, when I removed the conversion to lowercase, it fixed everything. Thank you for guiding me in the right direction! -
Filesize error - worked in php 4.2, not 5.1
TapeGun007 replied to TapeGun007's topic in PHP Coding Help
So... after playing around a bit more. The code still executes correctly and display the file names and sizes. Granted, your code that you had me put in says the file does not exists. Why would it say that the file is missing when it's clearly present? -
Filesize error - worked in php 4.2, not 5.1
TapeGun007 replied to TapeGun007's topic in PHP Coding Help
Ok... so that's weird. I get the File doesn't exist! like 1,000 times, and then it goes ahead and executes the code below and spits out the filenames and their sizes... how could the filename not exists and yet it executes fine? The original error was this: I didn't think any of that other info would be all that useful. I actually thought the code you gave me didn't mean anything since the files are obviously there and the path must be correct since it executes the code... this is where I'm puzzled. -
I have a folder with about 2,000 files in it. Most are .mp3's and .pdf files. The largest file is 50 MB. This line of code: $File_Size=filesize('Music_Library/'.$file); is causing this error: I add up the total file size so at the bottom of the page it will list the total number of files and total filesize that all files are taking up. Works fine on my old php 4.2 server, but simply gives this error on 5.1. Most of the help I found on Google doesn't seem to deal with my specific error.
-
Ah.... also had to change If (!in_array($row['GroupName'], $GroupArray)){ Works perfectly now! Thank you so much for pointing me in the right direction!
-
Hey, thank you for the quick reply. I didn't know about the in_array command. However, I did put in your code. This is the result I got (see image): [attachment deleted by admin]
-
Ok, I give up, I'm having a brain fart, and I know this has to be more simple that my brain is making it out to be. In the Database, I have a "group" field that contains this: Choir Chorale Directors Mass Choir Musicians Sign Choir Sound Crew Spanish Music Worship Leaders Worship Teams Youth Chorale Youth Worship Team When a person joins a group, their ID number is added to the group ID. So, when an admin loads up a particular user to see what groups they belong to, the webpage will spit out this information: The [remove] is simply where an admin can click and it just removes this user from the group. I store the groups that John Doe is a part of into an Array called $GroupArray for later use. Just below this, it shows all the groups they can become a part of: By clicking the [Add], the page will refresh and add this person to the group. However, what I really want to do, is if a person like John Doe belongs to the group "Choir", I do not want the "Choir" group to show up in the Add section. As it stands right now, you can click on the [Add] 6 times, and it would the person to the Choir group 6 times. Here is the code that adds the groups that John Doe already belongs to: <?php // Create an array, store the groups they are a part of, then do NOT display those same groups in the ADD section // this way you cannot add a person to a group more than once... and it looks great $grouparray=array(); $x=0; $result = mysql_query("SELECT * FROM GroupMember WHERE MemberID='$ID' ORDER BY GroupName"); while($row = mysql_fetch_array($result)){ $x++; $GroupArray[$x]=$row['GroupName']; echo "<tr><td>" . $row['GroupName'] . "</td><td><a href='members.php?list=edit&MemberID=$ID'>[ Remove ]</a></td><tr>"; } ?> Here is the part of the code that just simply displays all the groups, and it incorrect. <?php $result = mysql_query("SELECT * FROM Groups ORDER BY GroupName"); while($row = mysql_fetch_array($result)){ foreach ($GroupArray as $value){ If ($row['GroupName'] <> $value){ echo "<tr><td>".$row['GroupName']."</td><td><a href='members.php?list=edit&MemberID=$ID&GroupAdd=".$row['GroupName']."'>[ Add ]</a></td></tr>"; break; } } } ?> This last snippet just simply spits out all the groups. I only want it to spit out the groups that John Doe is NOT a part of. Please be gentle, I'm still a bit new to php. Hope this all makes sense. I have a picture so you can see it. [attachment deleted by admin]
-
>.< hmm... weird. I thought I had put an echo statement to show the year and it was coming up. Now it isn't at all. I simply assigned the year the correct value and it works fine. I'm not sure what I was seeing originally or what I did, but I must've made an error somewhere in my troubleshooting. LOL. Originally, I was getting an error on this: $days_in_month = cal_days_in_month(CAL_GREGORIAN, $month, $year) ; because $year had no value. I thought maybe cal_days_in_month had changed, so I echoed the $year to find it had no value. I then placed that echo command earlier and ... well... I thought it was returning a value... I guess not.
-
Hi, I have a very simple problem that I don't quite understand. In php 4.2, I could use this line: $year = $tempyear -1; works fine. However, in php 5.2 $year becomes equal to nothing. What's the correct way to write this code now?
-
I have converted a Access db into MySQL. One thing I would like to do, just for sake of clean up, is to renumber all the auto increments so there aren't huge gaps like there currently are. Currently, the auto increment unique ID is like 1,2,3,4,50,51,52, ect. I just want it to be 1,2,3,4,5,6,7. I have PHPAdmin, how can i do this?
-
Ah ok... thank you!
-
Is it possible to make a variable If statement? Example: If scenario1 = True Then $statement = "Date>CurrentDate" Else $statement="Date<CurrentDate" . . . If ($statement){ [output results] } Or... is there just a better way of doing this?
-
Aren't you really trying to increase more than just the rows? If it's only rows, then I made a mistake: echo "<td></td>"; should be replaced with: echo "<td rowspan='$row'></td>"; Regardless, if you are simply trying to make the rowspan and/or colspan a variable size, the HTML code is correct. It looks like, however, that you are also trying to increase the column span. You could literally have a variable width set for both such as: echo "<td rowspan='$row' colspan='$col'></td>";
-
Have you tried adding a quick phpinfo(); to your script to make sure that the hosting web server is actually providing the referer information?
-
What is causing the error in this block of code?
TapeGun007 replied to torquate's topic in PHP Coding Help
To turn on error reporting: To turn on Error Reporting in PHP, this is what I use. You can set this anywhere in your PHP code, but it has to be above the error or else it will not work. This is the easiest way and will work in most hosting environments: ini_set('display_errors',1); error_reporting(E_ALL|E_STRICT); or if you only want to see Warning Messages and not Notice Messages: ini_set('display_errors',1); error_reporting(E_ALL); -
echo "<td rowspan='$col'></td>" Is this what you are looking for?