Old 03-16-2006   #1 (permalink)
Registered User
 
MrProtoman's Avatar
 
Join Date: Aug 2004
Location: Evansville, IN
Posts: 70

Send a message via ICQ to MrProtoman Send a message via AIM to MrProtoman Send a message via MSN to MrProtoman Send a message via Yahoo to MrProtoman
File Listing

Okay, so I'm bored and decided to add some files to my website for my amusement. I went looking through my archived PHP tutorials and found one for listing file info from a directory, so I'm putting it to work in my downloads directory, which is just where I upload random crap to give to someone else. Everything was going well, until I started trying to add more to it. Here's the code:
PHP Code:
<?php
$path 
"downloads/"
$dir_handle = @opendir($path) or die("Unable to open $path"); 
while (
$file readdir($dir_handle)) { 
if(!
is_dir($file)) { 
$filesize round(filesize($path.$file)/1310722);
$mimetype mime_content_type($path.$file);
echo 
"Name: $file<br>File Size: [ $filesize MB ]<br>Mime: $mimetype<br><a href=$path$file>Download file</a><br>------<br>"


closedir($dir_handle); 
?>
and the output:
Quote:
application/x-zip Name: invboard1_2f.zip
File Size: [ 9.66 MB ]
Mime: application/x-zip
Download file
------
Now the part that's bugging me is the mime type displaying before Name:. Nothing should appear before that the way I understand it, because it's the only output/display type line. Everything else is function or alias asignment. While I can see why it would show before Name, I can't figure out why it's showing up at all. It's the in the same format as the alias above it. The only other thing in the file is the mime_content_type function because the actual PHP function of the same name doesn't work correctly on my server. I actually pulled this off the PHP.net comments about the function itself as a "if your function errors out, use this to simulate it instead" kind of thing.
PHP Code:
if ( ! function_exists 'mime_content_type ' ) )
{
   function 
mime_content_type $f )
   {
       return 
system trim'file -bi ' escapeshellarg $f ) ) );
   }

Looking at the preview before I post this, it apprears that the PHP bbcode tag parser agrees with Notepad++. There isn't anything missing from the code to mess it up. Any ideas?
__________________
MrProtoman is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 03-16-2006   #2 (permalink)
Registered User
 
Join Date: Apr 2005
Location: antwerp, belgium
Posts: 51

think you left a space to much in the f construction
PHP Code:
if ( ! function_exists 'mime_content_type ' ) ) 
should be
PHP Code:
if ( ! function_exists 'mime_content_type' ) ) 
it does the trick for me so
or atleast it removes some of the errors that i get, still no value for the mime type though
__________________

Last edited by sneeuwbal; 03-16-2006 at 10:28 AM.
sneeuwbal is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 03-16-2006   #3 (permalink)
Registered User
 
MrProtoman's Avatar
 
Join Date: Aug 2004
Location: Evansville, IN
Posts: 70

Send a message via ICQ to MrProtoman Send a message via AIM to MrProtoman Send a message via MSN to MrProtoman Send a message via Yahoo to MrProtoman
I'd actually already changed that in an attempt to fix it, though like I said, it came straight from some guy on the PHP.net page about that function. I went as far as skipping the variable and just calling the function where I need it in the code, but it still gives me two reports (Mime: application/x-zip application/x-zip).

I've since switched to a almost 200 line code to replace the above posted 7 that just compares the extension to a array of known extensions and their mime types, but I'd kind of like to know what's wrong with that one. Mine is more flexible, because I can add non-standard mime types like application/x-rar-compression for .RAR archives, and audio/x-ms-wmv for .WMV movies.
__________________
MrProtoman is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 03-17-2006   #4 (permalink)
Registered User
 
Join Date: Mar 2006
Posts: 3

theres a nice apache extensions out there: mod_dir

kshok is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 03-17-2006   #5 (permalink)
Registered User
 
MrProtoman's Avatar
 
Join Date: Aug 2004
Location: Evansville, IN
Posts: 70

Send a message via ICQ to MrProtoman Send a message via AIM to MrProtoman Send a message via MSN to MrProtoman Send a message via Yahoo to MrProtoman
It's a little hard to configure the layout/design of the default directory listing from mod_autoindex when you don't have root access to the server, or any kind of shell/ssh access for that matter.
__________________
MrProtoman is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Closed Thread

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
.PSD File Size Question Pho3niX Adobe Photoshop 10 04-27-2006 06:50 PM
PHP Uploading - File Size Errors ibanez270dx HTML / PHP / ASP / JS 4 02-10-2006 07:37 PM
Reducing kb (size of file) w/o reducing size of image jasonchan483 Adobe Photoshop 5 11-18-2005 09:20 PM
saving imageready file Statik Adobe Photoshop 4 07-09-2004 10:30 PM


All times are GMT +1. The time now is 09:07 AM.
Content Relevant URLs by vBSEO 3.2.0

Design & Content © BioRUST 2008 :: PRIVACY STATEMENT :: LEGAL INFORMATION :: ADVERTISING MEDIA KIT