Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 542
  • Last Modified:

Upload a whole folder via php, not just one file?

I have a client who thinks their users will want to upload an entire folder of files at once to save time. Assuming I've already set php.conf to handle this large load, how do I even go about doing this? As far as I know the only program that can upload a whole folder is ftp? Is there anyway to integrate php with ftp functions to get this result? Or is there some way for a user to indicate a path to their folder on their hard drive and using a directory listing alogorithm php just loops thru the folder on the clien'ts machine and uploads each document one at a time until it's done with the appearance of doing it at once to the user? any hacks at all? TIA!
0
PHPGoddess
Asked:
PHPGoddess
4 Solutions
 
laurlyCommented:
  the browser button in HTML will only let you upload a file not a hole directory so file upload with php is out of the question. PHP is server sided not client sided so looping though the files on the users pc isnt going to work eather.

even all the directory functions chdir and such isnt going to work becouse that is on the server hence serversided.  The only way the ftp fucntions would work would be if the users pc had an ftp server set up on it that you could use php to log into.

basicly i think your out of luck. but i sympathize with you managers always have these wonderful ideas of things that they need done with out considering the poor programer that has to figuer out how to do it.

good luck

laurly
0
 
rascalpantsCommented:
I say this posted somewhere and kept it...

I hope it helps:


Here is a sample function for copy a directory, and ALL subdirectories.

-----


function rec_copy ($from_path, $to_path) {
mkdir($to_path, 0777);
$this_path = getcwd();
if (is_dir($from_path)) {
chdir($from_path);
$handle=opendir('.');
while (($file = readdir($handle))!==false) {
if (($file != ".") && ($file != "..")) {
if (is_dir($file)) {

rec_copy ($from_path.$file."/", $to_path.$file."/");
chdir($from_path);
}
if (is_file($file)){
copy($from_path.$file, $to_path.$file);
}
}
}
closedir($handle);
}
}


just make your form variable match the above code or vice versa...


hope it helps...


rp
0
 
AmeristCommented:
PHP has no way to list all of the files in a directory on a remote machine.  Therefore it would be impossible to FTP those files (and thus the entire directory) to any server.  

                     ****                            
What you CAN do, however is zip the entire directory into a singe file, then upload it to the server. Then you can unzip it on the Server.   That would have the same effect.               ****                          

you can go here to get the unzip script you need to do this: http://www.phpconcept.net/pclzip/index.en.php 
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
s-maximCommented:

No,
there is no way you can use FTP directly from your users. FTP is a protocol itself, and this is not possible. PHP's FTP functions are intented for server2server connectons.

In any way, to get a whole folder from a user, you have three options:

1. Ask them to ZIP anything the upload. This way you can use PHP's ZIP functions to automatically unzip what they have sent and process the files the way you want

2. Provide multiple upload form so the user will be sending the file after file. Kinda boring if too many files are to send.

3. Create some sort of a client app (in C pr Java) that simply allows the user to browse their files online and, once selected a folder, to recursivelly POST the containing files on the webpage. This is not optimal as it envolves more staff, but might be a solution.


Maxim Maletsky
maxim@php.net
0
 
AmeristCommented:
Perhaps I was not clear enough.  

step 1.
Zip file gets uploaded to the server using PHP copy() function.

step 2.
Zip file gets FTP'd from the server to another server (if necessary)

step 3.
Zip file gets extracted and directory structure is re-created on target server.

Hope that clears up any confusion.
0
 
PHPGoddessAuthor Commented:
Thank you everyone, I will spend the next week attempting to implement all of your suggestions and which ever one is the most effective I'll award the points! Thank you!
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now