Important alert: (current site time 7/15/2013 9:50:57 AM EDT)
 

VB icon

File uploader/indexer

Email
Submitted on: 4/6/2002 2:53:37 PM
By: InteractiveWebGuys  
Level: Intermediate
User Rating: By 31 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 40638
author picture
(About the author)
 
     This code indexs files, uploads, and deletes. PLease vote for me!

 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
// for :File uploader/indexer
//**************************************
copyright 2001-2002 Interactive web Guys
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: File uploader/indexer
// Description:This code indexs files, uploads, and deletes. PLease vote for me!
// By: InteractiveWebGuys
//
// Returns:It out puts a table to the browser that shows each file.
//
// Side Effects:none as of now
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=594&lngWId=8//for details.//**************************************

<?php
error_reporting(0);
//this turns off error reporting we dothis so that we don't get a warning for the $action variable
$destination=".";
//the directory that the script index's if you want the current directory put a "." if you want another folder
//put "foldername"
if ($action=='delete')
{
$del = unlink("./$destination/$fle");
}
echo '<FONT SIZE="+2" COLOR="FF9A00"><CENTER>File manager</CENTER></FONT><BR><BR><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=o><TR><TD ALIGN=center WIDTH=200 bgcolor=FFECCE><CENTER>Filename:</CENTER></TD><TD ALIGN=center WIDTH=200 bgcolor=FFECCE><CENTER>Functions:</CENTER></TD><TD ALIGN=center WIDTH=200 bgcolor=FFECCE><CENTER>Filesize(in bytes):</CENTER></TD><TD ALIGN=center WIDTH=150 bgcolor=FFECCE><CENTER>Filetype:</CENTER></TD><TD ALIGN=center WIDTH=150 bgcolor=FFECCE><CENTER>Created on:</CENTER></TD></TABLE>';
 $directory = opendir($destination);
 while( $file = readdir( $directory ) )
 {
 $file_ar[] = $file;
 }
 foreach( $file_ar as $file )
 {
 if( $file == ".." || $file == "." )
 {
 continue;
 }
$type= strrchr($file,'.');
$name=$file;
$name2=$destination."/".$file;
if($type==''){$type='dir';}
$sizeoff=filesize($name2);
$time=date("D M j Y",filectime($name2));
if($time=='Wed Dec 31 1969'){$time='Unknown';}
if($sizeoff==''){$sizeoff='Unknown';}
if($sizeoff=='0'){$sizeoff='Unknown';}
$file2 = dirname($name2);
 if($color == "FF9A00") {
 $color = "FFECCE";
 } else {
 $color = "FF9A00";
 }
echo"<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=o><TR><TD ALIGN=center WIDTH=200 bgcolor='$color'><a href='$uname/$file' target=_blank>$name</a></font></TD><TD ALIGN=center WIDTH=200 bgcolor='$color'><A HREF='$PHP_SELF?action=delete&fle=$file&der=$uname'>Delete</A><TD ALIGN=center WIDTH=200 bgcolor='$color'>$sizeoff</TD> <TD ALIGN=center WIDTH=150 bgcolor='$color'>$type</TD><TD ALIGN=center WIDTH=150 bgcolor='$color'>$time</TD></TABLE>";
}
echo "<CENTER><FONT SIZE='+2' COLOR=\"FF9A00\"><BR><BR>Uploader</FONT></CENTER><BR><BR><FORM ACTION='$PHP_SELF' METHOD=post enctype=\"multipart/form-data\">File:<BR><INPUT TYPE='file' size='20' name='filename'><BR><CENTER> <input type=\"hidden\" name=\"action\" value=\"uploadProg\"><INPUT TYPE='hidden' name='action' value='upload'><INPUT TYPE='submit' value='Upload File'></CENTER></FORM>";
closedir($directory);
if($action==''){$action='noaction';}else{$action=$action;}
if($action=='upload')
{
 $filename==$filename_name;
 $action=('uploadprog');
 $destination=".";
 copy($filename,$destination."/".$filename_name);
 echo "<h2>File Uploaded.</h2>";
 echo "<HEAD><META HTTP-EQUIV='Refresh' CONTENT=1></HEAD>";
 }
 if ($filename=="none") {echo("<h1>No File Selected....</h1>"); break;}
 uploadProg($filename,$filename_name);
 break;
?>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
4/6/2002 11:28:34 PMkc

This code is excellent, well written and yet simple. I give it five globes! Good work!
~kc~
(If this comment was disrespectful, please report it.)

 
4/7/2002 9:58:40 AMEric

Well this was up and running in 5 minutes. Great job and thanks.


(If this comment was disrespectful, please report it.)

 
4/14/2002 10:59:03 AMD3ltaH0rse

Easy to use script and working in about 3 secs.

Cheers

http://clik.to/jezub

(If this comment was disrespectful, please report it.)

 
4/16/2002 8:26:52 AMInteractiveWebGuys

lol this is funny wil willmek you voted my code 1 globe yet everybody else voted me 5 are you trying to make my score go down?!!?! lol some people or should i say some people's kids..
(If this comment was disrespectful, please report it.)

 
4/17/2002 9:50:25 PMleet pSyCo

Smooth the rough edges... and what do you have? International usage. 5 globes most definately.
(If this comment was disrespectful, please report it.)

 
4/18/2002 2:49:31 AMJor

He PsychoGenius, DONT SCREW UP THIS SITE! I know you are rating other good codes with one globe. WE DONT LIKE CHEATERS HERE!
(If this comment was disrespectful, please report it.)

 
4/18/2002 7:27:40 AMInteractiveWebGuys

hmm tell wil wilimik that too he did the same thing to me rated my code with one globe, but yes psycho dont do that
(If this comment was disrespectful, please report it.)

 
4/19/2002 8:39:08 PMBrandon Pawoll

lol this code is cool! I just got into php a few days ago, already know alot. lol great job man.
(If this comment was disrespectful, please report it.)

 
4/30/2002 9:43:02 AMJor

I dont know what your doing but i dont like the fact that you are rating my code for the second time with bad ratings, the first time 1 globe and now two globes.
I you want to win the contest you should write better scripts so that you will get more votes instead of rating other codes with 1 globe!
(If this comment was disrespectful, please report it.)

 
4/30/2002 12:19:40 PMInteractiveWebGuys

heres the deal buddy..i rated your CODE ONE TIME UNO do you undertstand that. I rated it what i thought of it i dont give a crud how good my script is and i dont give a crud how good your script is. i also contacted planet-source-code about the rating thing and just TO LET YOU KNOW only the ratings that are 5 GLOBES AFFECT YOUR CODE!!!! so get off my back and get a life
(If this comment was disrespectful, please report it.)

 
7/10/2002 7:15:24 AMmki

How to upload a file when Server require username and pass. This program refresh many times, but doesn't upload.
(If this comment was disrespectful, please report it.)

 
7/11/2002 1:29:31 AMInteractiveWebGuys

hmm maybe because it wasn't designed for that? dontcha think?
(If this comment was disrespectful, please report it.)

 
8/19/2002 10:17:34 AMMark

I have entered the code exactly as it is on this page, no alterations. and uploaded to http://url.co.uk/directory

and the script displays the files in the table, but if I click one it is linking to http://url.co.uk without the directory! how can I fix this?
(If this comment was disrespectful, please report it.)

 
9/19/2002 10:44:23 PM

Up and runnnig as fast as can be! Great Script!
(If this comment was disrespectful, please report it.)

 
10/23/2002 3:10:12 AM

I love thi script.. but I need help. It does not seem to create a URL to the files location, it wont upload and no delete either, I have the php file in my webroot and it is pointing to my uploads/files folder, folder is writeable. I have no clue why. I am new to this. If some one could help i would be grateful. Thanx
(If this comment was disrespectful, please report it.)

 
10/31/2002 10:23:01 AM

I've emailed you about the file list pointing to the root address rather than the directory the files are contained in. Please fix it then I can give it five globes ;o)
(If this comment was disrespectful, please report it.)

 
11/6/2002 10:22:35 AM

This is realy the best.. up in 5 sec..

I love it !
(If this comment was disrespectful, please report it.)

 
12/6/2002 3:40:26 AM

It was not uploading at all, so i turned error_reporting(1), it is telling me the error lies within an undefined function uploadProg on line 57... please help...
(If this comment was disrespectful, please report it.)

 
12/14/2002 8:40:49 PM

Ive been looking for code like this for some time, but only just started using PHP so im a bit of a NooB. I've got the file working but when i click the UPLOAD FILE button the next page is a bad URL any help on this??

Tnx in adance

Smoker :)
(If this comment was disrespectful, please report it.)

 
2/19/2003 2:04:02 PM

First of all, nice script!

Now..I've needed something like this for a Xoops Module I have been trying to develop for a private clan site to allow members to upload their weapons packs. I have mangaged to create the module using this code, but..it only will accept the "." directory. What I would like it to have there be a sub-dir of the script folder that has the files. (i.e. "/files")

Perhaps I need more coffee, but haven't been able to make it work. Any ideas?

Thanks!
(If this comment was disrespectful, please report it.)

 
3/21/2003 11:22:22 AM

I, like others I have seen reply on here, copied the code exactly, it displays the files, but I cannot upload anything. It just refreshs the page. I see others are having this problem, but nobody has posted a solution.
(If this comment was disrespectful, please report it.)

 
3/31/2003 2:52:02 PM

sexy
(If this comment was disrespectful, please report it.)

 
5/4/2003 9:50:13 PM

hey mate, it works sweet with a bit of tweeking with the directery etc, but it uploads everything sweet images etc, but it doesnt seem to liek large file sizes? liek anything much over 2Mb ? its not the server as far as i know! what do you suggest? thanks slinky! sr_slinky@yahoo.co.uk, you can see it here: http://www.slinky-designs.co.uk/general/upload.php
(If this comment was disrespectful, please report it.)

 
5/4/2003 9:52:19 PM

hey mate, i got it all working here:

http://www.slinky-designs.co.uk/dj/upload.php

but it dont like large file sizes? it uploads it but doesnt show or go onto the server? can you halp me out mate? cheerts
Slinky sr_slinky@yahoo.co.uk
(If this comment was disrespectful, please report it.)

 
5/7/2003 1:58:58 PM

my server admin says there should be a variable in the code to allow me to allow the size to be more than 2mb if needed
(If this comment was disrespectful, please report it.)

 
5/27/2003 4:58:42 PM

I tried out the
(If this comment was disrespectful, please report it.)

 
5/27/2003 5:00:02 PM

I tried out the "File uploader/indexer" and it works nicely with a Linux server but I'm having problems getting it to work for the nonprofit where it needs to work on a Windows server. I thought I could change the "/" "\" but that hasn't worked. Do you have any 'hints?.' This is for a private staff intranet site. Not the public area. Thanks, Kent
(If this comment was disrespectful, please report it.)

 
5/31/2003 11:12:49 PM

Thanks for writing this great script!

Two problems:
1.) Script will not successfully upload a file larger than about 2 MB.
2.) Error on undefined function uploadProg()

Any fix or advice would be most welcomed.
(If this comment was disrespectful, please report it.)

 
6/23/2003 7:55:49 AM

To get around the 2MB issue, check out what I've posted on my site, it's about PHP.ini and .htaccess files, this problem effects almost all PHP scripts but isn't too dificult to fix..

http://www.methlabs.org/tips/phpuploader.htm
(If this comment was disrespectful, please report it.)

 
4/2/2004 2:37:26 PMPeter van Velzen

Hmm, Simple code but not enough functions... 2 globes
(If this comment was disrespectful, please report it.)

 
9/3/2004 11:38:09 AM

KUWWWAAAAA..GREAT WORK DUDE!!!!
(If this comment was disrespectful, please report it.)

 
3/2/2005 10:09:23 PMwrongprotocol

the common reason why it seems to "refresh" itself is because the new PHP versions seem to have better "security" and do not allow files to be written, even if File uploading is On in php.ini....I have been working on this problem for 2 days because I need it for a business project I have been working on. I'll keep ya posted.
(If this comment was disrespectful, please report it.)

 
5/2/2006 10:46:48 AMselecta

Nice, thanks! If you want to restrict filtype and size do something like snippet below. You certainly do not want users to be able to upload php scripts to your site!!! { $filename==$filename_name; // Check extention and size $extension = substr(strrchr($filename_name, "."), 1); $max_size = "5000000"; //in KB $file_size = filesize($filename); if ($extension <> "mp3" || $file_size > $max_size) { echo "

File not uploaded. Only MP3 files under ".$max_size." KB allowed.

"; echo "

Extention: ".$extension." / Filesize: ".$file_size." KB

"; } else { $action=('uploadprog'); $destination="."; copy($filename,$destination."/".$filename _name); echo "

File Uploaded.

"; echo " "; } }
(If this comment was disrespectful, please report it.)

 
11/19/2006 9:14:38 PMkev

excellent script, anyone know how to password protect this or password protect the upload section
(If this comment was disrespectful, please report it.)

 
11/27/2008 4:24:28 PMerasmo

great
(If this comment was disrespectful, please report it.)

 
6/18/2009 11:44:39 PMniru

hey i tried this code but it just didn't work .. It shows the screen and contains but when i upload the file it just didn't show that file in folder. and it also doesn't delete file if i copy file to that folder. Plz help..
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.