Below is code that I have been using. I can get everything to work correctly except for what is in Red. I can edit directly where just a single file is uploaded, but when I do an array, it won't work.

$foldername = "". $_REQUEST['ID'] ."";

      if(!is_dir("photos/$foldername"))
      {mkdir ("photos/$foldername", 0777); 
      chmod ("photos/$foldername", 0777);}
      else {}  

      $resourcefolder = "photos/"; 
      $filestocopy = "array";

      $filestocopy[0] = "file1.php"; 
      $filestocopy[1] = "file2.php"; 

      $link = mysql_connect("localhost", "username", "password") or die("Could not connect to server!");          
      $sql=mysql_query("INSERT INTO folders ('" . $foldername . "') VALUES ('" . $foldername . "')"); 

      [COLOR=Red]$frompath = "photos/"; 
      $topath = "photos/$foldername/";
      if(copy($frompath, $topath))[/COLOR]

    Try this:

          $frompath = "photos/"; 
          $topath = "photos/".$foldername."/";

    You have to put a period (.) inbetween the variable $foldername and the directory name inorder to combine the string to the variable.

      You only need to do that for single quotes not double quotes.

      $filestocopy = "array";
      

      should be

      $filestocopy = array();
      

      You haven't specified the filename in the from or the to path or looped through the array.

      If you are just moving the files rather than copying use rename()

        This is an error that I get using the below code with changes that you recommend.

        Warning: copy(photos/6013702/): failed to open stream: Is a directory in httpdocs/upload.php on line 85

        This is my newest script

        //Creates ID folder in the upload directory
                  $foldername = "". $_REQUEST['ID'] ."";
        
              if(!is_dir("photos/$foldername"))
              {mkdir ("photos/$foldername", 0777); 
              chmod ("photos/$foldername", 0777);}
              else {}  
        
              $resourcefolder = "photos/"; 
              $filestocopy = array();
        
              $filestocopy[0] = "phpslideshow.php"; 
              $filestocopy[1] = "template.html"; 
        
              $link = mysql_connect("localhost", "username", "password") or die("Could not connect to server!");          
              $sql=mysql_query("INSERT INTO folders ('" . $foldername . "') VALUES ('" . $foldername . "')"); 
        
              $frompath = "photos/"; 
              $topath = "photos/".$foldername."/";
              if(copy($frompath, $topath))
        
          $frompath = "photos/"; 
                    $topath = "photos/".$foldername."/";
                    if(copy($frompath, $topath))
          

          You can't copy folders or the contents of entire folders in one go.

          You need the files names so you need to loop through the array of filenames and copy them one at a time e.g.

          $frompath = "photos/"; 
          $topath = "photos/".$foldername."/";
          
          foreach ($filestocopy as $value)
          {
          copy ($frompath.$value,$topath.$value);
          }
          

            That's awesome, it works!!!! And I still have a few hairs left on my head. Thanks a bunch ClarkF1, and thanks to everyone else here.

              Write a Reply...