Browser Uploading

apps

#1

I work on my website from school, and they’ve recently blocked all ftp ports, so even passive FTP protocols won’t work. Is there anyway I could set up a PHP script so I could upload files without FTP?


#2

Yeah, you can do that. You will need to create an HTML form that will upload the file for you. Be sure to include the intended PATH for the new file as one of your fields. Create a PHP script to handle the file once it has been uploaded. Here’s an example of the form:

[code]

Upload Form

Upload Form

Browse your local directory:
Provide a path for your file:

[/code]Your PHP script will need to check that the extension is legitimate, and that the filename/path combination is not already in use by another file. Then you copy the file to the new location. You can determine information about the file from the following variables: [code]$_FILES['userfile']['name'] // original filename $_FILES['userfile']['tmp_name'] // path and filename of temporary file $_FILES['userfile']['size'] // size of file (in bytes) $_FILES['userfile']['type'] // MIME type of file[/code]Copying the file (actually, you move it) is easy. Create a variable [b]$filename[/b] that includes the path, filename, and extension of the new file, and then move it with the following: [code]move_uploaded_file($_FILES['userfile']['tmp_name'], $filename);[/code]I hope that helps.

Simon Jessey
Keystone Websites | si-blog


#3

you might want to think about setting up some htaccess security of that form (or page rather) as well, so that not just any shumck can upload stuff, and trash your site.

-Matttail


#4

Woo…Thanks alot =D

And ya, I’d do the security thing. Maybe password the page or something.


#5

Just wanted to let anyone who might be interested know that Invision has a free program that can handle this. You have to make accounts and such to run it. It’s php based, and requires no mySQL db, so I’m guessing it just runs on a txt file or something, too lazy to read into it though. It’s secure though, you can upload, edit, delete, etc. It’s alot like the file manager from cPanel too.