?
Solved

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

Posted on 2003-02-21
8
Medium Priority
?
540 Views
Last Modified: 2010-05-18
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
Comment
Question by:PHPGoddess
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 2

Accepted Solution

by:
laurly earned 200 total points
ID: 7994576
  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
 
LVL 22

Assisted Solution

by:rascalpants
rascalpants earned 200 total points
ID: 7995530
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
 
LVL 1

Assisted Solution

by:Amerist
Amerist earned 200 total points
ID: 7998072
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
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 
LVL 1

Assisted Solution

by:s-maxim
s-maxim earned 200 total points
ID: 7999250

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
 
LVL 1

Expert Comment

by:Amerist
ID: 8000939
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
 

Author Comment

by:PHPGoddess
ID: 8003370
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question