PHP Help (Upload Script)
1 Attachment(s)
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 :p |
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. |
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. |
1 Attachment(s)
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++) { 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 |
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 . "/"; |
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. |
All times are GMT -5. The time now is 07:34 PM. |
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2024, vBulletin Solutions, Inc.