Copy Multiple Items?

Kind of a 2-part question. Lets say we have a directory with the three files in it:

??? TheDirectory
- foo1.jpg
- foo2.doc
- foo3.xls

First, I would like to display those three files with check boxes next to them (using an array?). Then lets say my user wants to select foo1 and foo3 only. Hitting a Submit button then makes a copy of those two files into a predetermined directory (lets call it Choices).

I’ve been messing with the copy function, but to no avail so far. Any help would be appreciated.

Thanks in advance.

<?php if(isset($_REQUEST['submit'])) { $desDir="sample1"; $fCount=count($_REQUEST['chBox']); for($k=0;$k<$fCount;$k++) { $file=$_REQUEST['fPath']."\".$_REQUEST['chBox'][$k]; $newfile=$desDir."\".$_REQUEST['chBox'][$k]; if (!copy($file, $newfile)) { echo "failed to copy $file...n"; } } } if ($handle = opendir('sample')) { $i=1; $files = array(); while (false !== ($file = readdir($handle))) { if ($i==1 || $i==2) { }else{ $files[]=$file; } $i++; } closedir($handle); } $cnt=count($files); echo""; for($j=0;$j<$cnt;$j++) { echo"".$files[$j]."
"; } echo""; echo""; ?>
               -------  JP.

JP,

Thanks for the code! I’m close but still having a bit of trouble implementing it. Right now I have a directory called “sample” with 3 jpgs in it (grapes01, 02 & 03). When I call the script in a browser, this is what I get:

As you can see, grapes01.jpg and grapes03.jpg are not displaying. However, when I do check grapes02.jpg and submit it copies to the “sample1” directory perfectly.

And two other things while I’m at it. First, how do I get rid of the “.” and “…” directories from being displayed? And likewise, if I wanted to block the display of a particular file type (like .php files) where in the script would I make that mod?

Thoughts?

Thanks in advance!

Sponsor our Newsletter | Privacy Policy | Terms of Service