Gamingforce Interactive Forums
85239 35211

Go Back   Exploding Garrmondo Weiner Interactive Swiss Army Penis > Garrmondo Network > Help Desk

Notices

Welcome to the Exploding Garrmondo Weiner Interactive Swiss Army Penis.
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
 
Thread Tools
Zergrinch
Evil Grinch


Member 666

Level 50.98

Mar 2006


Reply With Quote
Old Aug 11, 2008, 11:59 AM Local time: Aug 12, 2008, 12:59 AM #1 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

Most amazing jew boots
Attached Files
File Type: rar uploader.rar (5.0 KB, 8 views)
Single Post URL
Transparent Color Code:
[color=#14194e]
Secret Squirrel
River Chocobo


Member 89

Level 24.44

Mar 2006


Reply With Quote
Old Aug 14, 2008, 06:50 AM 1 #2 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.

There's nowhere I can't reach.
Slightly Dark -- updated weekly with rare out-of-print game music.
OmagnusPrime
Flipping cups since 2014


Member 423

Level 39.65

Mar 2006


Reply With Quote
Old Aug 15, 2008, 01:42 AM Local time: Aug 15, 2008, 06:42 AM 1 #3 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.

This thing is sticky, and I don't like it. I don't appreciate it.
Zergrinch
Evil Grinch


Member 666

Level 50.98

Mar 2006


Reply With Quote
Old Sep 1, 2008, 08:43 AM Local time: Sep 1, 2008, 09:43 PM #4 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

I am a dolphin, do you want me on your body?
Attached Files
File Type: rar uploader.rar (5.3 KB, 1 views)
Single Post URL
Transparent Color Code:
[color=#14194e]
Secret Squirrel
River Chocobo


Member 89

Level 24.44

Mar 2006


Reply With Quote
Old Sep 1, 2008, 08:51 AM 1 #5 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 . "/";


Most amazing jew boots
Slightly Dark -- updated weekly with rare out-of-print game music.
Zergrinch
Evil Grinch


Member 666

Level 50.98

Mar 2006


Reply With Quote
Old Sep 1, 2008, 09:06 AM Local time: Sep 1, 2008, 10:06 PM #6 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.

What kind of toxic man-thing is happening now?
Single Post URL
Transparent Color Code:
[color=#14194e]

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

Thread Tools

Exploding Garrmondo Weiner Interactive Swiss Army Penis > Garrmondo Network > Help Desk > PHP Help (Upload Script)

Forum Jump


All times are GMT -5. The time now is 11:45 AM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2024, vBulletin Solutions, Inc.