Pandemonium
Aug 24 2004, 04:46 PM
Okay, this script takes in an uploaded file from a form, adds it to the web server, and then it adds it to the correct alphabetical letter directory (ie. Active would go in the a directory). The only use I see for it would be for making it easier to find something when it is uploaded. This script takes two .php files: upload.php and upload-check.php. If you are going to use the script, you can rename those files to whatever you want. So, here's the script. Use it at your own discretion (as always). upload.phpCODE <?php
echo "<form action = 'upload-check.php' method='post' enctype='multipart/form-data'>"; echo "<input type = 'text' name='nameOfFile'>"; echo "<input type = 'file' name='uploadFile'>"; echo "<input type = 'submit' value = 'Send'>"; echo "</form>";
?> upload-check.phpCODE <?php
$letterArray = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
$arraySize = array_count_values($letterArray);
for($n = 0; $n <= $arraySize; $n++) { if(!is_dir($n)) { mkdir('somefolder/' . $n, 0666); } }
if(strlen($_POST['nameOfFile']) > 1 and substr($_FILES['uploadFile'], -4) != '.exe') { for($i = 0; $i <= $arraySize; $i++) { if(substr($_FILES['nameOfFile'], 1) == $i) { $tmpFile = $_FILES['uploadFile']['tmp_name']; $dest = "http://yourwebsite.com/somefolder/" . $i . "/" . $_FILES['uploadName']['name']; copy($tmpFile, $dest); } } } else { echo "Sorry, but your file name was either too short or it had an invalid file extension. Please go back and try again."; }
?>
Reply
Spectre
Aug 24 2004, 06:01 PM
It's just an idea, but I generally like to keep all of it together in a single file. You could achieve this by combining the scripts as shown below, but ensuring that only one portion is executed at a time (hence the need for the use of the if statement, and the exit function). CODE <?php
if(!isset($_POST['uploadFile'])) { echo "<form action = 'upload.php' method='post' enctype='multipart/form-data'>"; echo "<input type = 'text' name='nameOfFile'>"; echo "<input type = 'file' name='uploadFile'>"; echo "<input type = 'submit' value = 'Send'>"; echo "</form>"; exit; }
$letterArray = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
$arraySize = array_count_values($letterArray);
for($n = 0; $n <= $arraySize; $n++) { if(!is_dir($n)) { mkdir('somefolder/' . $n, 0666); } }
if($_POST['nameOfFile'] < 1 and substr($_FILES['uploadFile'], -4) != '.exe') { for($i = 0; $i <= $arraySize; $i++) { if(substr($_FILES['nameOfFile'], 1) == $i) { $tmpFile = $_FILES['uploadFile']['tmp_name']; $dest = "http://yourwebsite.com/somefolder/" . $i . "/" . $_FILES['uploadName']['name']; copy($tmpFile, $dest); } } } else { echo "Sorry, but your file name was either too short or it had an invalid file extension. Please go back and try again."; }
?>
Reply
Pandemonium
Aug 24 2004, 06:20 PM
Good point, Spectre. I suppose I forgot about the is_set() function. Thanks for the "improvement".
Reply
Triple X
Aug 24 2004, 06:22 PM
Hm interesting, good work. I should keep this in mind for when I get my sub-domain.
Reply
Zenchi
Aug 25 2004, 12:22 AM
I was just curious, but what is the reason to exclude exes? (Or am I reading this wrong? ^^;) CODE if($_POST['nameOfFile'] < 1 and substr($_FILES['uploadFile'], -4) != '.exe')
Reply
Pandemonium
Aug 25 2004, 01:00 AM
QUOTE(Zenchi @ Aug 24 2004, 08:22 PM) I was just curious, but what is the reason to exclude exes? (Or am I reading this wrong? ^^  CODE if($_POST['nameOfFile'] < 1 and substr($_FILES['uploadFile'], -4) != '.exe') I excluded .exe as an example. It just shows you how to protect against certain file types. I just chose .exe randomly.
Reply
Zenchi
Aug 25 2004, 01:06 AM
QUOTE(Pandemonium @ Aug 24 2004, 08:00 PM) QUOTE(Zenchi @ Aug 24 2004, 08:22 PM) I was just curious, but what is the reason to exclude exes? (Or am I reading this wrong? ^^  CODE if($_POST['nameOfFile'] < 1 and substr($_FILES['uploadFile'], -4) != '.exe') I excluded .exe as an example. It just shows you how to protect against certain file types. I just chose .exe randomly. Ah.. that's very neat.  I'm going to go disect that part of the code and figure out what it does. ^^
Reply
Spectre
Aug 25 2004, 04:44 AM
As for the first part: CODE if($_POST['nameOfFile'] < 1 I would assume that is to check that $_POST['nameOfFile'] (which is passed to the script from the form) does actually have a value. The fact that an integer comparison is used sort of makes it a little confusing though. I would have used either: CODE if($_POST['nameOfFile']) // (because if a variable has an assigned value, then it will be returned as true) or if($_POST['nameOfFile'] != "" // or if(isset($_POST['nameOfFile']) But that's just me. CODE substr($_FILES['uploadFile'], -4) != '.exe' This uses the substr(); function to select the last 4 characters of the filename entered, and then makes sure that are not '.exe'. Substr(); is used to select a certain portion of a string, eg: CODE substr("My name is Spectre", 3) Will select all of the characters, starting at postion 3, so it would become 'name is Spectre'. Using a negative integer, eg. -4, will select the last -4 characters of the string. In an IF statement, 'x == y' means that 'x' is equal to 'y' (double equals sign is intentional), and 'x != y' means that 'x' is not equal to 'y'. Hope that sort of explains it for you. Checking the filename is certainly a good idea, but a binary check would be much more secure.
Reply
Pandemonium
Aug 25 2004, 04:00 PM
QUOTE(Spectre @ Aug 25 2004, 12:44 AM) As for the first part: CODE if($_POST['nameOfFile'] < 1 I would assume that is to check that $_POST['nameOfFile'] (which is passed to the script from the form) does actually have a value. The fact that an integer comparison is used sort of makes it a little confusing though. I would have used either: CODE if($_POST['nameOfFile']) // (because if a variable has an assigned value, then it will be returned as true) or if($_POST['nameOfFile'] != "" // or if(isset($_POST['nameOfFile']) But that's just me. CODE substr($_FILES['uploadFile'], -4) != '.exe' This uses the substr(); function to select the last 4 characters of the filename entered, and then makes sure that are not '.exe'. Substr(); is used to select a certain portion of a string, eg: CODE substr("My name is Spectre", 3) Will select all of the characters, starting at postion 3, so it would become 'name is Spectre'. Using a negative integer, eg. -4, will select the last -4 characters of the string. In an IF statement, 'x == y' means that 'x' is equal to 'y' (double equals sign is intentional), and 'x != y' means that 'x' is not equal to 'y'. Hope that sort of explains it for you. Checking the filename is certainly a good idea, but a binary check would be much more secure. Spectre, about $_POST['nameOfFile'] < 1. I forgot 2 things here: First, it was supposed to be strlen($_POST['nameOfFIle']) < 1, and second, it's not supposed to be < 1, it's supposed to be > 1. I made two mistakes in that piece of code. Sorry about that.
Reply
Similar Topics
Keywords : alphabetical, file, sort, script
- Php Guest Online Script
(2)
Internal File Transfer
(5) Is there some kind of file transfer utility that can be used within the intranet for file
transfers..? We have so much need for such an utility here in my work place.... The problem with
what we are using is very big... we are basically using skype in my workplace and the problem with
that is it happens with the internet... So whenever i transfer files via skype it occupies the
bandwidth.... which is very bad since we have a limited bandwidth connection. So... What i require
is a utility where the transfer happens within the network and not via the internet. So... if ....
Phpizabi Social Network Script
(1) Hello everyone not been on for AGES! we had net problems and i had to move to qupis and now
I've got problems. I'm making a social networking site using this script and I cant get it
to install Everytime I go to the install page i get this QUOTE Warning: session_start() :
open_basedir restriction in effect. File(/home/kasiks1/tmp) is not within the allowed path(s):
(/home/karlos:/usr/lib/php:/usr/local/lib/php:/tmp) in
/home/karlos/public_html/phpazi/install/index.php on line 1 Fatal error: session_start() : Failed
to initialize storage module: file....
How To Make A View New Post Script?
(5) Ok so i'm still working on the forum software i posted about a while back, but I have no idea
how to do this. I want to make a view new post script, as this is one of the main things that my
forum software dose not have that all other forums have. so does any body have an idea on how i
would do this? Thanks.....
Free Software For File Recovery
RECUVA (3) Hi all, I was loking for a software to recover my lost files and I found this /biggrin.gif"
style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> And the best part is ,
its free Recuva - File Recovery Recuva (pronounced "recover") is a freeware Windows utility to
restore files that have been accidentally deleted from your computer. This includes files emptied
from the Recycle bin as well as images and other files that have been deleted by user error from
digital camera memory cards or MP3 players. It will even bring back files that have been d....
Where Is The Bookmarks File Stored With Ff2?
(4) My bookmarks are critical and lengthy. I'd like to save them to a flash drive, since my laptop
is ancient and it's been acting up lately. I went into the FireFox folder, but couldn't find
the bookmarks info anywhere. there's a bookmarks.html page, but it doesn't contain the
actual bookmarks. Where does FF2 store the bookmarks? Or is there an easier way to copy and paste
the bookmarks to another file? /huh.gif" style="vertical-align:middle" emoid=":huh:" border="0"
alt="huh.gif" /> 2 poor 4 a sig ....
Guessing Php Script
(0) I am looking for: freeware php quess the person in the photo game script....
Debug Exe Files
How to debug an exe file. (4) Think that we have written a program, and some codes are wrong. We can go back to compiler and
change the code, and compile again. But I will show you how to correct our mistakes without using
the compiler. Let's start: I have written a program in Delphi. Let's see my mistake. I
have created a form like this. After this I wrote the codes in the Compare Button click as
below. CODE 1. procedure TForm1.ComparebuttonClick(Sender: TObject); 2. var
3. a,b:integer; 4. begin 5. a := StrToInt(EditA.Text); 6. b :....
Webmail Server Script
(2) Hi Guys! A friend of mine came to me asking me to help him write code for his server so that
his clients can go on his site and create a webmail account. I told him I'm not a programmer but
I googled the subject. I ran into SquirrelMail and was impressed with what it could do. Going
through the documentation I saw this QUOTE There are only two requirements for SquirrelMail:
A web server with PHP installed. PHP needs to be at least 4.1.0. Access to an IMAP server which
supports IMAP 4 rev 1. I have php5 running on my XPproSP3 but I don't know....
A Good File Explorer For Windows Xp?
what's a better alternative to explorer (6) Hi, although it has some useful features and it's (i'd hope so...) well integrated with the
shell, the file explorer that comes with windows xp is not the best we can ask for... so I've
always tried to use various other pieces of softwares randomly found on the net whenever I've
had to intensively work on my file directory... still I haven't found a very good one, all
those I tried have some kind of bug or they are not really user friendly in some occasions... would
anyone suggest a good FREEWARE file explorer? thanks /wink.gif" style="vertical-al....
Need Help Installing Dolphin Community Script!
(5) I'm not sure if this is the right place to post this but I really need help in installing the
dolphin community script. I have absolutely no previous experience of scripts or programming. I
would really appreciate if someone could walk me through it step-by-step, or even do it for me by
logging into my cpanel. I have tried to install it my self but I'm a little confused. I'm
sure it won't take very long at all for someone who has done this before.....
Question Regarding File Transfer!
FILE TRANSFER (4) Hi friends, I am looking for a secure and robust file transfer web service. I am handling a sales
force which is stationed at different locations and is frequently moving. They need to upload there
activity reports frequently to our servers. So I am looking for an easy to use secure and robust
file transfer web service which can be used by my sales force for their needs. Thanks & Warm
Regards. ....
Loaing Script
(3) hello, I'm looking for a preloader script for my site. like it will display an loading
image while the site is loading and the once the page has loaded the image will disapear. i tryed
searching for one on google but i could not find one, i think i searched for the worng thing. if
some one knows how to make one or where i can find one that would be great. Thanks....
Invite Script..
(2) I didn't know where else to put it /sad.gif" style="vertical-align:middle" emoid=":("
border="0" alt="sad.gif" /> If moderators find another forum more suitable plz move this one
/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> I am looking
for some sort of sript or program that let's people on your website invite friends. Like they
put in their Emailadress and mails are send to everyone in their list.. I hope someone can help me
/sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /> Greetzz....
Background Image Swap Script
Change a Background Image based on clock time (15) Background Image Changer Script To swap the background image from your CSS file according to the
Server Clock Time. 1.) In your CSS file, add the following rule: CODE body {
background: url(time.png); } 2.) Create a "folder" named time.png. 3.) Into the
folder, place three images named morning.png, day.png, night.png. 4.) Also, in the same folder,
create an index.php file and copy/paste the following script. CODE <?php $hour =
date('H'); if ($hour < 12 ) { $image =
"morning.png"; } ....
Html Code Tester. Online Script
(15) Yes, yes. I have another script that I have written and I am distributing. I am not entirely sure if
this works. I have not tested it yet, but I will later and post back with a demo and fix it up.
Current script: CODE <?php //Save this as something like htmltest.php function
CheckForm() { $html_unsafe=$_POST['code']; //Gives us our user
input $html_safe=str_replace("<?php"," ",$html_unsafe);
//Starts security measures $html_safe=str_replace("?>","
",$html_sa....
Windows Ntfs Folder And File Compression. Good Or Bad?
(6) I believe everyone in this forum knows what a file system means and that every windows user knows
what FAT and NTFS means so I am not gonna start going into those. Well, the NTFS (Windows NT file
system) offers a few advantages over the good ol' FAT (File allocation table) file system one of
which is the files and folders compression. This I have done quite a number of times to save disc
space (and it really does save some disc space). i am using my computer as an example here. Consider
my 35GB partition which is carrying my Windows Vista Operating sys and has less ....
Read File (.txt) On Another Website Using Jsp?
(3) in my jsp program,i need to read a file (.txt) on another website,how can i do this? thanks a lot.
shorten title ....
A Trap17 How-to Guide For Beginners
Something for those who can't get enough of the Trap17 Readme file (12) I am not entirely sure if this the right place to post about this, but here goes anyway... For
those who find themselves slightly (or considerably more than slightly) clueless about where to get
started after getting a hosting account, here is an user guide that might potentially help you
out. I wrote it out of three hours, so forgive me if it's clumsy, but I'm hoping that a few
people here may find it useful. Feedback is greatly appreciated /smile.gif"
style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> I'm planning to build on
a FAQ....
How To Open A .daa File
(36) Hi there, How do i have to open a file with extension .daa Somebody told me to copy it on cd and to
run it from cd rom but i got the same problems. What dp i need to do to ppen the file? Thanks....
Linux Question: Amarok And File Permissions
please help, i can't get it to work with all music files (4) hey, i use to use Linux DC++ to download music from some hubs and i usually download it to
/home/downloads/ and then i move the files to my collection on another HDD a sata one, on
sda3/music/ but when i move the files using krushader root mode they become posessed by root and
amarok can't play them displaying a locker on the file's icon. I tried to " chmod 774 music
", where music is my music directory, as root in konsole but no luck. What should i do to make a
whole directory accessible from amarok as user?....
Watermark Your Image With Simple Php Script
found it on the net (34) This script was found on the net http://tips-scripts.com/?tip=watermark#tip B&T's Tips &
Scripts site. Just in case the site may not show, I will include the code here: List of things
needed: 1. your image in any format 2. watermark image--in gif format with transparent background 3.
script below with name (i.e. watermark.php) CODE <?php // this script creates a watermarked
image from an image file - can be a .jpg .gif or .png file // where watermark.gif is a mostly
transparent gif image with the watermark - goes in the same directory as this script // ....
How To Put Music In The Background Of A Powerpoint Presentation
without having the viewer download the music file (9) Well, i made this power poit presentation in memory of my grandfather as many of you kno, passed
away exactly a week ago....and i am trying to get this song to play as background music..and i did,
but there is one humongus problem... in order for the people who are viewing it to hear the
background music they have to download the music file as well ad the powerpoint presentation, which
on my DSL conntection taked almost 2 minutes, and i could just imagine what it will be for a dial-up
user (my grandma who wants to see it)... Some people may say, its impossible, but i kn....
Simple C File Handling In Action
Small code snipet which covers most of basic file handling and navigat (3) Yesterday I suddenly got a lot of work. The same work we try to push off, yes you are right all
formalities to get the code review incorporated and update all source code files with code review
headers. Imagine if you need to open 300 files one by one and append code review headers at the
end. Since most files are reviewed in groups of 20 to 30 files. We require one header to be placed
in say 20 to 30 files. To simplify I went back to my class assignment days and wrote this small c
utility to open all files passed on command line and open attach code review headers an....
Transfer File Of Any Size Using Winsock Control
Winsock Help (5) This tutorial shows how to transfer file of any size using winsock control. - Open VB; - Select
standard exe; - Press Ctrl + t to show the add component window; - Select winsock control and
microsoft common dialog; - Add one winsock control in the project; - Name it winsock1; - If you want
to add chat then add another winsock and name it winsock2; - Insert another winsock object if you
want to add chat also; - Add a microsoft common dialog box; - Name it cd; - We will use this
winsock1 object to transfer the file and winsock2 for chat; ------------- The basic idea : ....
Import From Excel File Into Mysql Database
(7) Has anyone tried using the excel import function that comes with phpmyadmin
http://www.phpmyadmin.net/home_page/ - it does not require any additional plug-ins or scripts and
is fairly straightforward to use. In phpmyadmin, if you click on the database table which you wish
to import the data to , there is a link on the bottom left corner which says "insert data from a
text file into the table" - although it says text file it still can be used to import an excel file.
When you click on this link you will be taken to a page where you will be asked for the file name
(the....
My File Manager Is Working
(2) I tried to change the html for my site in file manager but it just has the default page - the one
when you activate your site. /sad.gif' border='0' style='vertical-align:middle' alt='sad.gif' />
How do i change files?....
Free Weather Feed Script
(1) If you are tired of providing your clients with weather feeds that take visitors off of their site
or slam their site with ads, I finally found one after searching for hours.
Here's a link to a
FREE php script that pulls the feed directly from any airport in the world to your site. It is easy
to customize and has simple, well documented installation instructions.
http://www.mattsscripts.co.uk/mweather.htm
hope you find it helpful... a good one for designers
to archive as you will most likely need it some day for a client.
Check out Matt's other free
scripts....
Php Quiz Script
Make quizzes for your site. (20) Hello all, A little bit back I decided to make a quiz scriptjust out of no where lol. However it
doesnt do anything special but I am going to make an email mod for it so that it will email results
to your email address. So here is the basis of it. INSTRUCTIONS: Open a new page in your text
editor and paste in the following code. CODE <?php $qid = "Quiz ID-00"; ?>
<html> <head> <title><? echo "Gamers Pub $qid";
?></title> </head> <body> <p><h3><? echo "....
Could Someone Make A Php Script For Me?
Script to manage clans and players (3) Does someone know a script where you can 1. Add clans to a roster 2. Edit clans on a roster 3. Add
players too a clan 4. Edit players 5. Schedule matches 6. Add clan Leaders to manage their own clan
+ members 7. Add members to edit their own information And maybe some sort of scoreboard integrated
where you can put Wins, Draws and loses and that automaticly puts best clans on the top? If there
isnt such a script could someone create 1 for me? (its for a league ^^)....
Looking for alphabetical, file, sort, script
|
|
Searching Video's for alphabetical, file, sort, script
|
advertisement
|
|