Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jun 2004
    Location
    Los Angeles, CA
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    uploading entire dir

    Hello,

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

    thanks, Jay

  • #2
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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).

  • #3
    New Coder
    Join Date
    Jun 2004
    Location
    Los Angeles, CA
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #4
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes, I told you how in my post.

  • #5
    Regular Coder goughy000's Avatar
    Join Date
    Nov 2005
    Location
    England
    Posts
    415
    Thanks
    0
    Thanked 0 Times in 0 Posts
    can't you use FTP?

  • #6
    New Coder
    Join Date
    Jun 2004
    Location
    Los Angeles, CA
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #7
    Regular Coder goughy000's Avatar
    Join Date
    Nov 2005
    Location
    England
    Posts
    415
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 Code:
    <?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++
       }
    }
    ?>

  • #8
    Registered User
    Join Date
    Sep 2005
    Posts
    315
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 !

  • #9
    Regular Coder goughy000's Avatar
    Join Date
    Nov 2005
    Location
    England
    Posts
    415
    Thanks
    0
    Thanked 0 Times in 0 Posts
    added a chmod as recomended by arne

    PHP Code:
    <?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++ 
       } 

    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •