Forum Moderators: coopster

Message Too Old, No Replies

upload folder not file

is this possible?

         

StickeR

3:58 pm on Aug 19, 2006 (gmt 0)

10+ Year Member



My client wants a php script which allows the user to not upload a single file through the filefield in a form, bu to upload an entire folder.

I told him I thought this wasn't possible, but I like the idea.
I searched the net and all I found was that it is impossible to retreive data from a local folder.
e.g. readdir only reads dirs from the server, it I could somehow index the local folder, I could loop the files tp upload, but this seems to be impossible to do.

I was wondering if anybody has any experience or info on getting files from a clients hard disk?

Habtom

6:25 pm on Aug 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PHP is a server side script. I don't believe that it is possible for PHP to access a local hard disk unless it is supported by any other script probably Javascript.

Hab

henry0

7:34 pm on Aug 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Before anything build a GUI where the client will
enter a directory name (the dir that he wants to be uploaded)and use mkdir() to create a new dir on the server.

First you clould ask the client to create in a easy location a new dir "my_uploads"
so we know where it is located

Ask him to copy the dir to be uploaded in the "my_uploads" dir

Next open the local dir using opendir()
Grab all file names and extension
Use copy() to copy file/s
since you know $source and $destination

you might be in business

needs to work on it but it might (at very first glance!) work.

StickeR

1:13 am on Aug 20, 2006 (gmt 0)

10+ Year Member



Thanks for the advice, the thing is, which I forgot to mention that it's not my client but his customers who must be able to upload the folder.
This can not be done by regular ftp (we're not giving away server info), nor must they be able to upload anything else than jpeg files.

Since so far it seems impossible to read the folder from users HD, for now they will get a single file upload option.
With the additional option to upload a Zip containing several images, which is automatically unzipped on the server.

[edited by: StickeR at 1:13 am (utc) on Aug. 20, 2006]

opifex

5:21 am on Aug 20, 2006 (gmt 0)

10+ Year Member



why not create an ftp directory with separate users for this one function? fewer steps for everyone

jatar_k

7:01 am on Aug 20, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



honestly, it just doesn't work, nor should it

if you want users to be able to upload a whole dir

give them step by step instructions on how to zip it, then give them an upload form

vincevincevince

7:22 am on Aug 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Option 1 (IE ONLY):
For IE users you can create a new FTP account to a special folder. Have your PHP script open an IFRAME with ftp://username:password@domain.foo/folder as the SRC. This will open the FTP interface within the webpage. Ask them to then drag-and-drop their folder into the 'box below'.

Ask them to press 'continue' when the upload is complete.

Use PHP to take that FTP uploaded folder (most of them won't even know it was an FTP upload they just did!) and move it wherever it is meant to be.

Option 2 (Requires Basic Technical Expertise):
Ask them to right click the folder and Send to -> Compressed folder. This (zip) file can now be uploaded as a single file. PHP can open the zip file, but I recommend just using a shell command, something like `unzip file.zip` to do it once uploaded

Option 3 (Requires software installation):
Build a small downloadable app to undertake the steps involve in option 2. If it's a commonly undertaken action have it added to the 'send to' context-menu list (Send to -> YourService). If it's only a once-in-a-while task then have them 'browse for folder' in the downloaded app, click okay, and watch the file transfers zip past. Many ways to do the upload here, I'd recommend zipping it and transfering it by POST/multipart-form encoding.

henry0

10:50 am on Aug 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Mostly one can't unzip on a nix server unless using a shell comm but the users will not have that knowledge and/or for ex:PuTTy.

I remember many threads discussing using PHP to unzip it always ends by: "Use PuTTy"

vincevincevince

12:04 pm on Aug 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just have php run
`unzip whatever.zip`

(using the ` quotes)

It should work fine!

henry0

12:47 pm on Aug 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes of course

But: On two major Hosts - both running a dedicated server-

I was told that I would not be able to do it.
One of them where I still have a server was that very site host :)

Out of curiosity I will try again.