Gamingforce Interactive Forums
Day 4 - 21 days until Christmas

Go Back   Gamingforce Interactive Forums > Gamingforce Computing > Help Desk
Register FAQ GFWiki Members List Donate Arcade ChocoJournal Mark Forums Read

Welcome to the Gamingforce Interactive Forums.
GFF is a community of gaming and music enthusiasts. We have a team of dedicated moderators, constant member-organized activities, and plenty of custom features, including our unique journal system. If this is your first visit, be sure to check out the FAQ or our GFWiki. You will have to register before you can post. Membership is completely free (and gets rid of the pesky advertisement unit underneath this message).


PHP Help (Upload Script)
Reply
 
LinkBack Thread Tools
Ugliest Sigs in GFF


Member 666

Level 39.27

Mar 2006


Reply With Quote
Old Aug 11, 2008, 12:59 PM Local time: Aug 12, 2008, 12:59 AM #1 (permalink) of 6
PHP Help (Upload Script)

I'm currently using the attached upload PHP script to quickly upload files into my webspace. It has most of the features I desire, like optional password protection, ability to restrict certain file types, and multiple uploads at once.

However, there's a sorting feature I kinda want, but have absolutely no idea how to do. Currently, the script dumps everything into its current directory. Is it possible to set it up such that certain file types get put in certain folders?

For example, if you upload .PNG .GIF or .JPG, it will save the files to \pictures. If you upload .TXT .DOC .XLS .PPT, it will save the files to \documents. If you upload .RAR .ZIP, it will save it to \archives.

Is this kind of thing possible? If so, how do I shot web?

Thanks in advance
Attached Files
File Type: rar uploader.rar (5.0 KB, 8 views)
Join the Gamingforce Composition Competition

Useful Stuff
  1. Show Single Posts http://www.gamingforce.org/forums/showpost.php?p=
  2. Transparent Color-Code I lost it
  3. Who Ignored Signatures

River Chocobo


Member 89

Level 23.57

Mar 2006


Reply With Quote
Old Aug 14, 2008, 07:50 AM 1 #2 (permalink) of 6
It's definitely doable, and probably isn't overly difficult so it should make a good little project for you to learn php.
  • Split the string $file_name[$i] and grab everything after the period (the extension)
  • Create a big if..then...elfseif block and compare that extension name to the types of files you're allowing to be uploaded (txt, jpg, etc.)
  • In each branch of the if statement, take the variable called $folder, and set it equal to the appropriate folder name (txt,jpg,etc.)

That should be all you need to do, barring any surprises.
Slightly Dark -- updated weekly with rare out-of-print game music.
Prime Gamer


Member 423

Level 30.77

Mar 2006


Reply With Quote
Old Aug 15, 2008, 02:42 AM Local time: Aug 15, 2008, 06:42 AM 1 #3 (permalink) of 6
What Squirrel said pretty much covers what you'll need to do. If you do your split on '.' then you should be able grab the last section to get your extension. Actually there may be a built in way of grabbing the extension, but I can't remember off the top of my head.

What I would change, is don't use an if/else block, use a switch statement and use drop through to avoid having to re-write lots of code to set the folder name unnecessarily.
Ugliest Sigs in GFF


Member 666

Level 39.27

Mar 2006


Reply With Quote
Old Sep 1, 2008, 09:43 AM Local time: Sep 1, 2008, 09:43 PM #4 (permalink) of 6
Alrighty, I've taken your suggestions and put a whole chunk of conditionals using the SWITCH command.

The files uploaded magnificently.

BUT there is one problem. After the files are uploaded, the script echoes their URL. This is the code that does so:

Code:
For($i=0; $i <= $file_uploads-1; $i++) {
	If($_FILES['file']['name'][$i]) {
		$file=$i+1;
				Echo("<b>File #".$file.":</b> <a href=\"".$full_url.$file_name[$i]."\" target=\"_blank\">".$full_url.$file_name[$i]."</a><br /><br />\n");
	}
}
It's basically using $full_url, which is static compared to the $folder which I changed with a bunch of conditionals.

What's the best way of going about this?

The new version, plus code I've inserted, is attached.
A test implementation exists at jetUpload - Powered By phUploader
Attached Files
File Type: rar uploader.rar (5.3 KB, 1 views)
Join the Gamingforce Composition Competition

Useful Stuff
  1. Show Single Posts http://www.gamingforce.org/forums/showpost.php?p=
  2. Transparent Color-Code I lost it
  3. Who Ignored Signatures

River Chocobo


Member 89

Level 23.57

Mar 2006


Reply With Quote
Old Sep 1, 2008, 09:51 AM 1 #5 (permalink) of 6
You could just tack the foldername onto the end of the url by sticking this line in front of the Echo:

Code:
$full_url .= $folder . "/";
Slightly Dark -- updated weekly with rare out-of-print game music.
Ugliest Sigs in GFF


Member 666

Level 39.27

Mar 2006


Reply With Quote
Old Sep 1, 2008, 10:06 AM Local time: Sep 1, 2008, 10:06 PM #6 (permalink) of 6
Nada, it am fail

Edit: I gave up and recopied the entire SWITCH block right before the echo. It seems to work!

Thanks for the assist, Secret Squirrel.
Join the Gamingforce Composition Competition

Useful Stuff
  1. Show Single Posts http://www.gamingforce.org/forums/showpost.php?p=
  2. Transparent Color-Code I lost it
  3. Who Ignored Signatures


Last edited by Zergrinch : Sep 1, 2008 at 10:12 AM.
Reply


Thread Tools

Gamingforce Interactive Forums > Gamingforce Computing > Help Desk > PHP Help (Upload Script)

Forum Jump



All times are GMT -5. The time now is 02:31 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0