Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP script fine tuning -- likely a simple fix
Old 08-14-2008, 07:26 PM PHP script fine tuning -- likely a simple fix
Skilled Talker

Posts: 90
Trades: 0
Hi all,

I'm trying to configure this script entitled Czar New File... essentially it lists the 5 newest files added to a directory. Anyways, I have it configured nearly to the point of completion, but when you click the link of the file, it errors because it's trying to call the web address and the root directory on top of it.

But enough of my poor explanation.... here's the problem:
http://www.foothillsbaptist.org/new08/resources.htm
(Just try clicking either of the two listed files)

and here's the code:
PHP Code:
<body link="#133980">

<?
##########################################
### 
### CzarNewfile v1.01
### Made by: Czaries  [czaries@pacbell.net]
### http://www.czaries.net/scripts/
### for more scripts and updates.
###
##########################################

### How many files to show? ###
// i.e. "Newest 5 Files", "Newest 10 Files", etc...
$filelim "5";

### Directory to look in for files ###
/*
Directory, from the base http URL your files are in.
Include BOTH starting and trailing slashes ( / ).
i.e. If your files are at http://yoursite.com/downloads,
    put "/downloads/" - WITH BOTH SLASHES!
*/
# $checkdir = "/"; // base directory (http://yoursite.com/)
$checkdir "/home/**USER**/public_html/new08/downloads/2008/ministries/adult discipleship/"

### File extensions to include ###
// Turns feature "on" or "off"
$extlim "off";
/*
Allows you to limit which types of files will be included
Separate each by quotes/comma, you may use as many as you like
INCLUDE the beginning period ( . )!
Note: Only includes text from the LAST period on (i.e. If you want to
include ".tar.gz" files, put ".gz" only.  This is a bug that not even the
PHP file extension function can read, and it something that cannot
be fixed without extensive coding)
*/
# $extarr = array(".exe", ".zip", ".rar"); // Only accepts EXE, ZIP, and RAR files
$extarr = array(".exe"".zip"".rar"".gz"".sit"".hqx");

### Table Properties ###
// Width of output table
$tblwidth "150"// can be a number, or a percent
// Background color of output table
$tblbg ""// hexidecimal format (i.e. "#FFFFFF") 






### No need to edit below this line ###


### Put starting & trailing slash on incase user forgot
if(strrpos($checkdir"/") != (strlen($checkdir)-1)) { $checkdir .= "/"; }
if(
strpos($checkdir"/") != "0") { $checkdir "/$checkdir"; }
### Get full root path of the file directory
$filedir "$DOCUMENT_ROOT$checkdir";
### Get the name of this file, without the beginning slash
$thisfile basename($PHP_SELF);
### Make sure directory exists
if(!file_exists($filedir)) { print "No such directory!<br>Check to make sure the \$checkdir variable is correct.<br><br>Current: \$checkdir = \"$checkdir\";"; exit; }
### Open folder, get file names and load them into an array
if ($handle opendir($filedir)) {
    while (
false !== ($file readdir($handle))) { 
        if (
$file != "." && $file != ".." && $file != $thisfile && !is_dir("$filedir$file")) {
        if(
$extlim == "on") { 
        if(
in_array(strrchr($file"."), $extarr)) {
        
$farr[$file] = date ("U"filemtime("$filedir$file"));
        }
        } else {
        
$farr[$file] = date ("U"filemtime("$filedir$file"));
        }
        }
    }
closedir($handle); 
}

### Check to make sure there are actually items in the folder
$farrc count($farr);
if (
$farrc != "0") {
if(
$farrc $filelim) { $filelim $farrc; }
?>
<!-- CzarNewfile v1.01 -->
<font face="arial" size=10 color="#133980">
<table width="<? print $tblwidth?>" border="0" cellspacing="0" cellpadding="0"<? if($bgcolor != "") { print " bgcolor=\"$tblbg\""; } ?>>
<tr><td colspan="3"><? echo "<b>Newest $filelim Files</b><br>\n"?></td></tr>
<?
### Sort by date, descending
arsort($farr);
$limset "1";
### Print each result
foreach($farr as $filename => $date) {
    if(
$limset <= $filelim) {
    print 
"<tr><td nowrap>$limset)&nbsp;</td><td><a href=\"$checkdir$filename\">$filename</a>&nbsp;</td><td nowrap>[" date ("n/j"$date) . "]</td></tr>\n";
    
$limset++;
    } 

print 
"</table>\n";
} else {
print 
"
<!-- CzarNewfile v1.01 -->
There are currently no files to display!
"
;
}
?>
<!-- CzarNewfile made by Czaries - www.czaries.net -->

</body>
Thanks in advance!
msaz87 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-15-2008, 02:08 AM Re: PHP script fine tuning -- likely a simple fix
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
<a href=\"$checkdir$filename\">
$checkdir is the absolute path to your files directory. You should output the path relative to your server's document root.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 08-15-2008, 02:27 AM Re: PHP script fine tuning -- likely a simple fix
Skilled Talker

Posts: 90
Trades: 0
Sorry... I'm not exactly sure what you mean by outputting the path relative to the server's document root?
msaz87 is offline
Reply With Quote
View Public Profile
 
Old 08-15-2008, 02:48 AM Re: PHP script fine tuning -- likely a simple fix
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
change
PHP Code:
$checkdir "/home/**USER**/public_html/new08/downloads/2008/ministries/adult discipleship/"
to
PHP Code:
$reldir "/new08/downloads/2008/ministries/adult discipleship/";
$checkdir "/home/**USER**/public_html".$reldir
and then later in <a href=\"$checkdir$filename\"> replace $checkdir with $reldir.

I can make some errors but I hope you are smart enough to get the idea and correct them.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 08-15-2008, 03:22 AM Re: PHP script fine tuning -- likely a simple fix
Skilled Talker

Posts: 90
Trades: 0
Worked like a charm... thanks!
msaz87 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP script fine tuning -- likely a simple fix
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.34707 seconds with 12 queries