How to upload a folder

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
chakhar86
Forum Commoner
Posts: 45
Joined: Mon Jun 05, 2006 1:36 am
Contact:

How to upload a folder

Post by chakhar86 »

I need to upload a folder (with or without sub-folder) to a server folder.

Or, if I want use a HTML INPUT FILE FORM, can I make the "Open file dialog" can accept folder?

Thanks men...
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

negative :-(

Best you could do is design some sort of flash or java applet that helped the user select multiple files
chakhar86
Forum Commoner
Posts: 45
Joined: Mon Jun 05, 2006 1:36 am
Contact:

Post by chakhar86 »

I have this Idea..

first, create a folder in server with the same name of folder that user wants to upload.
next, read the content of the folder
next, depends on option wheter the user wants to upload the sub-folder, we can use recursive or just ignore the sub-folder (check the sub-folder with is_directory())
next, upload each file just like usual, use copy()
end of algorithm

Only the problem is, the user has to type the folder he/she wants to upload, I want to eliminate this not user-friendly method...

Please help me ASAP....

ps: I have write the code but I lost it, so I give u the algorithm
chakhar86
Forum Commoner
Posts: 45
Joined: Mon Jun 05, 2006 1:36 am
Contact:

Post by chakhar86 »

Or, can we read the client computer folders?
If we can how you do that?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Both your suggestions are essentially the same thing. PHP is a server side language and is not aware of the client. To read the files from the client's computer you'll likely need to use a java applet.

The best PHP could do in this situation is have the user zip of their directory, and upload it to the server which will then decompress the file.
chakhar86
Forum Commoner
Posts: 45
Joined: Mon Jun 05, 2006 1:36 am
Contact:

Post by chakhar86 »

How bout javascript?

And if its impossible, then where I should learn Java applet (are the clients must have JRE installed in their computer to read the applet?). I prefer Javascript then...
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

javascript's security layer will prevent what you want to do - you'll have to use either flash or a java applet. I'd recommend flash since you're already sort of familiar with javascript AND there's probably a tutorial / codebase out there already.

Google "flash folder upload" or something similar
chakhar86
Forum Commoner
Posts: 45
Joined: Mon Jun 05, 2006 1:36 am
Contact:

Post by chakhar86 »

I got this Idea...

idea 1:
-use Javascript to read the folder in local disk
-user select the folder
-before submitting, there a java script that modify values of HTML input tag (I believe it can be done), this will make browser upload multiple (and I think PHP can accept multiple files upload)
-if the folder has sub-folder, maybe we can alter the name for tagging

idea 2:
-use Javascript to read the folder in local disk
-user select the folder
-Javascript zip the folder and toss it to HTML input tag
-submit it
-then let php unzip the folder

can those be done?

thanks
chakhar86
Forum Commoner
Posts: 45
Joined: Mon Jun 05, 2006 1:36 am
Contact:

Post by chakhar86 »

Kieran Huggins wrote:Google "flash folder upload" or something similar
Can't find it, do you know exact site?
But I still prefer using javascript because the user won't have install anything in his/her computer (almost all browser support javascript right?). But if there is no other way, maybe flash is the best way (its lighter than JRE I think).
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

chakhar86 wrote:I got this Idea...

idea 1:
-use Javascript to read the folder in local disk

...

idea 2:
-use Javascript to read the folder in local disk

...
Both areas are impossible, as previously stated. Consider the security implications javascript could actually read the users harddrive..
chakhar86
Forum Commoner
Posts: 45
Joined: Mon Jun 05, 2006 1:36 am
Contact:

Post by chakhar86 »

so, the last thing that can be done is using flash?
can u show me how?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I personally never bothered with flash, but I'm sure if you checked out http://www.hotscripts.com you'd probably come across something useful. To be honest, I didn't think flash was allowed permission to the client harddrive.. the only things I've come across are java applets.
Post Reply