|
|
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).
|
|
Thread Tools |
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 |
It's definitely doable, and probably isn't overly difficult so it should make a good little project for you to learn php.
That should be all you need to do, barring any surprises. There's nowhere I can't reach. |
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. |
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"); } } 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? |
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 |
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?
Last edited by Zergrinch; Sep 1, 2008 at 09:12 AM.
|