Use a variable. You'll need to pass/determine the folder name somehow.

When I do this:
$uploadedfolder = dirname($_SERVER[/ name of uploaded folder / ].'/');
mkdir( "path/'.$uploadedfolder.'/new_folder",0700 );

It creates new_folder on the same level as the main folder(the uploaded folder). I need new_folder to sit inside main folder not outside of it.

    crump;11012017 wrote:

    It creates new_folder on the same level as the main folder(the uploaded folder).

    That's probably because this:

    $_SERVER[/* name of uploaded folder */ ]

    doesn't exist. Did you create that variable first? It doesn't sound like one of the predefined indexes that PHP populates, so unless you manually specified it earlier in the script somehow, it should make sense that it doesn't exist.

      [font=monospace]/ name of uploaded folder /[/font] was a comment - a description of what you need to put there. How do you know what the name of the uploaded folder is? However you figure that out (name of the zip file, name of the root dir after extracting, etc.), the result is what you need to use here.

        Yes, I understand / name of uploaded folder / was a comment. I placed $filename in there, which is the name of the uploaded file, but it still created the new folder on the same level as the main folder and not inside it. I don't have a problem creating folder I just don't know how to put it where I want it to go.

        So, it does this:
        -main folder
        -new folder

        when I want it sit inside:
        -main folder
        --new folder

          are you sure [font=monospace]$filename[/font] contains the desired directory name? Have you printed it out to check?

          Out of curiosity, how are you setting the value of [font=monospace]$filename[/font]? The only place I've seen you mention it so far is here, where you set it -inside a conditional statement- using [man]glob/man (which doesn't really make any sense):

          $filename = glob($dir . $value);

          honestly, I'm willing to bet it's empty

            What makes even less sense is that it sounds as if you've got:

            $_SERVER[$filename]

            unless I'm misunderstanding your last reply.

              Sorry, it's $file_name not $filename. When I echo $file_name it returns main_folder.zip not main_folder. This is a script to upload and unzip and how I'm setting value for $file_name.

              if(isset($_FILES["zip_file"]["name"])) { 
              		$file_name = $_FILES["zip_file"]["name"];
              		$temp_file = $_FILES["zip_file"]["tmp_name"];
              
              	$target_path = "path/to/folder/".$file_name; 
              	if(move_uploaded_file($temp_file, $target_path)) {
              		$zip = new ZipArchive();
              		$x = $zip->open($target_path);
              		if ($x === true) {
              			$zip->extractTo("path/to/folder/"); 
              			$zip->close();
              			$uploadedfolder = $file_name;
              			mkdir('path/to/folder/'.$uploadedfolder.'/new_folder/', 0700); 
              		};
              
              	};
              
              };

              Doing this won't create "new_folder" at all:

              $uploadedfolder = $file_name;
              mkdir('path/to/folder/'.$uploadedfolder.'/new_folder/', 0700); 

              Doing this will create "new_folder" but not on the level that I want, that is I want it to sit inside the uploaded folder. Right now, "new_folder" is sitting on same level as the uploaded folder ("main_folder"). How do I move it inside "main_folder?"

              $uploadedfolder = dirname($file_name);
              mkdir('path/to/folder/'.$uploadedfolder.'/new_folder/', 0700);

                What does your code look like?

                EDIT: Woops.. viewing wrong page.

                  crump;11012049 wrote:

                  Doing this will create "new_folder" but not on the level that I want, that is I want it to sit inside the uploaded folder. Right now, "new_folder" is sitting on same level as the uploaded folder ("main_folder"). How do I move it inside "main_folder?"

                  $uploadedfolder = dirname($file_name);
                  mkdir('path/to/folder/'.$uploadedfolder.'/new_folder/', 0700);

                  well, [font=monospace]dirname( 'main_folder.zip' )[/font] returns a dot ( . ), so your final path is [font=monospace]path/to/folder/./new_folder[/font] - same as [font=monospace]path/to/folder/new_folder[/font], which is what you're getting.

                  if you just want to use the name of the .zip as the directory name, just remove the extension:

                  mkdir( 'path/to/folder/'.basename( $file_name ).'/new_folder/',0777 );

                    Thanks for your help, but no go. :-( Like my last code it created "new_folder" but not residing where I want it to.

                    It's still giving me this (new_folder is same level as main_folder):
                    path/to/folder/new_folder

                    When I want this (one more level in):
                    path/to/folder/main_folder/new_folder

                      Omg. I made this way too hard on myself. All I had to do was this:

                      mkdir('path/to/image/' .$img_dir . '/new_folder/', 0777);

                      $img_dir is the variable I want to use not $file_name. Anyway, "new_folder" now sits inside "main_folder." However, even though this code works I'm thinking maybe I should use rename() instead of copy() to "move" files.

                      $img_dir = new RecursiveDirectoryIterator("path/to/image/"); 
                      foreach(new RecursiveIteratorIterator($img_dir) as $file) {
                          if (in_array(basename($file), $diff)) {
                              mkdir('path/to/image/' .$img_dir . '/new_folder/', 0777); 
                              $old_dir =  path/to/image/' . $img_dir . '/old_folder/'. basename($file);
                              $new_dir = path/to/image/' . $img_dir . '/new_folder/'. basename($file);      
                      if (copy($old_dir,$new_dir)) { unlink($old_dir); }; }; };

                        regarding [man]copy/man vs. [man]rename/man, yes, definitely. copy() takes longer, and it leaves the original file in place (which I don't think is what you intend).

                          Thanks! I changed code to rename(). I have another question. The following code will get all the basenames values in img src (and poor attempt at preg_match). However, if I want to ignore/skip over all img src values starting with "http://" and their basenames how would I do that?

                          foreach ($images as $image) {
                          		$src = $image->getAttribute( 'src' );
                          		  if(preg_match($src, '^(http|https|ftp)://') !=0){
                                  	     $arr[] = pathinfo( $src,PATHINFO_BASENAME ); 
                          		  };
                          };
                            // if(preg_match($src, '^(http|https|ftp)://') !=0)
                            if( preg_match( '#^(http|https|ftp)://#',$str ) === false )

                              $str should be $src? Doesn't seem to like #. Also tried this but didn't work: if( preg_match( '#src="(http://["]+)#', $src) === false ).

                                crump;11012167 wrote:

                                $str should be $src?

                                YES. sorry for the typo. unfortunately, my [edit post] button has gone.

                                crump;11012167 wrote:

                                Doesn't seem to like #

                                how so? the # character shouldn't be causing problems.

                                crump;11012167 wrote:

                                Also tried this but didn't work: if( preg_match( '#src="(http://["]+)#', $src) === false ).

                                sorry, we should be testing for [FONT=monospace]0[/FONT], not [FONT=monospace]false[/FONT]:

                                // if(preg_match($src, '^(http|https|ftp)://') !=0) 
                                //if( preg_match( '#^(http|https|ftp)://#',$str ) === false )
                                if( preg_match( '#^(http|https|ftp)://#',$src ) === 0 ) // tested. testing is important.

                                  ...or anything falsy:

                                  if(!preg_match('#^(https?|ftp)://#', $src)) // returns number of matches (0 or 1) or false in case of error

                                    Either one works. Thank you very much.

                                      Hi, I'm kinda stuck. Currently when you click upload it will spit out number of images found and a list of the names of those images. If I have multiple html files how do I show the names of html files and images associated to that html file? Currently, I have this:

                                      "3 images found:"
                                      a1.gif
                                      a2.gif
                                      3.gif

                                      But, if I have multiple html files I want to show:

                                      6 images found:

                                      test1.html test2.html etc...
                                      a1.gif a4.gif
                                      a2.gif a5.gif
                                      a3.gif a6.gif

                                      I know I would want to use a foreach loop but I'm not sure how/what to use in the html portion. Would I need to write a function for the PHP code below? I have a feeling my code is not the elegant solution.

                                      /* PHP /

                                      $dir = "path/";
                                      $imgs = glob($dir . "*.{jpg,gif,png}", GLOB_BRACE);
                                      
                                      foreach($imgs as $img){ 
                                          $arr1[] = pathinfo( $img,PATHINFO_BASENAME ); 
                                      };
                                      
                                      foreach (glob("path/*.{html, htm}", GLOB_BRACE) as $path){ 
                                      	$dom = new DOMDocument;
                                      	$dom->preserveWhiteSpace = false;
                                      	@$dom->loadHTMLFile($path);
                                      	$images = $dom->getElementsByTagName('img');
                                      
                                      foreach ($images as $image) {
                                      	$src = $image->getAttribute( 'src' );
                                      	if(!preg_match('#^(https?|ftp)://#', $src)) {
                                                	       $arr2[] = pathinfo( $src,PATHINFO_BASENAME ); 
                                      	};	
                                               };  	
                                       };
                                      
                                      $diff = array_diff($arr1, $arr2);
                                      
                                      $img_dir = new RecursiveDirectoryIterator("path/");
                                      foreach(new RecursiveIteratorIterator($img_dir) as $file) {
                                      	if (in_array(basename($file), $diff)) { 
                                      
                                         $old_dir = 'path/' .$img_dir . '/images/'. basename($file);
                                         $new_dir = 'path/' .$img_dir . '/new_folder/'. basename($file);
                                      
                                         if (isset($_POST['submit'])) {
                                      	$selected_radio = $_POST['group'];
                                      	if ($selected_radio == 'save'){
                                      		mkdir('path/' .$img_dir . '/new_folder/', 0700); 
                                      		rename($old_dir,$new_dir);
                                      
                                      	 }else if($selected_radio == 'delete'){
                                      		 unlink($old_dir);				
                                      	  };
                                      	};
                                       };
                                      };
                                      };
                                      

                                      /* HTML /

                                      <form method="post">
                                      <input type="file" name="zip_file" />
                                      <input type="submit" name="upload" value="upload" />
                                      <?php
                                      if (isset($_POST['upload'])) {
                                      foreach(){ // Here I want to show names of html files and a list of found images associated with that html file

                                              	 echo '<div>'.count($diff). '  images found: '. '</div>';
                                      	 echo '<div><ul><li>'. implode('</li><li>', $diff) .'</li></ul></div>';
                                               };
                                      }else if (isset($_POST['submit'])){
                                      	$selected_radio = $_POST['group'];
                                      	if ($selected_radio == 'save'){
                                      		echo '<div>'.count($diff). ' images saved to folder!'. '</div>';
                                      			}else if($selected_radio == 'delete'){
                                      				echo '<div>'.count($diff). ' images deleted!'. '</div>';
                                      	};
                                      };				

                                      };
                                      ?>

                                        <input type="radio" name="group" value="save">Save to folder<br />
                                        <input type="radio" name="group" value="delete">Delete<br /><br />
                                        <input type="submit" name="submit"  value="submit" />

                                      </form>

                                        Figured it out. Was way easier than I thought.