...

View Full Version : uploading entire dir



axeldrummer
02-17-2006, 04:40 AM
Hello,

Just curious if anyone knows a way for php to upload an entire folder/dir at once?

thanks, Jay

fci
02-17-2006, 06:32 AM
short answer, no.

it's possible to upload multiple files at once but that probably isn't what you want. one alternative is if people uploaded a zip file that was decompressed on the server (which does raise a few security concerns but I'm still throwing it out there).

axeldrummer
02-17-2006, 11:53 AM
Thanks!

Specifically, I have a folder of almost a hundred files with various names. I want to upload these into my host and this folder will contain these same exact files except that they will be nicely renamed numbers 1 through 100 or whatever .

I can only click and browse each one after another on my giant form, then hit upoad for the hundred files.

Is there any way to shorten this process?

fci
02-17-2006, 03:27 PM
yes, I told you how in my post.

goughy000
02-17-2006, 04:44 PM
can't you use FTP?

axeldrummer
02-18-2006, 12:59 AM
yeah, another alternative is to use FTP all the files at once, and then rename them all by numbers.

Is there a way to loop through a folder to rename files? Specifically, is there a way to check how many files there are? (when to end the loop)

Appreiate it a ton

goughy000
02-18-2006, 10:25 AM
oky dokey...

FTP up all your files then place the following php code in the same dir with the filename filerenamer.php this is important!



<?php
// list files from DIR into an array
$filelist = glob("*.*");

// set this var for later
$filenum = "1";

// Go through each file in turn
foreach($filelist AS $file){

if($file == "filerenamer.php"){
// Its this file, do nothing...
}else{
// Its not this file, carry on..

// Get file extension
$extension = end(explode("." $file);

// Echo filename
echo "$file -> ";

// Rename file
rename("$file", "$filenum.$extension";

// Echo new filename
echo "$filenum.$extension<br />";

// Add one to $filenum
$filenum++
}
}
?>

arne
02-18-2006, 06:22 PM
I think you'll also have to chmod all your pages to 777 or something else. I think the script won't get permission if you don't !

goughy000
02-18-2006, 07:28 PM
added a chmod as recomended by arne


<?php
// list files from DIR into an array
$filelist = glob("*.*");

// set this var for later
$filenum = "1";

// Go through each file in turn
foreach($filelist AS $file){

if($file == "filerenamer.php"){
// Its this file, do nothing...
}else{
// Its not this file, carry on..

// Get file extension
$extension = end(explode("." $file);

// Echo filename
echo "$file -> ";

// Chmod to 777
chmod("$file", 0777);

// Rename file
rename("$file", "$filenum.$extension";

// Echo new filename
echo "$filenum.$extension<br />";

// Add one to $filenum
$filenum++
}
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum