-1
  $ha=opendir($LOCAL_SERVER_DIR);

  while (($filelocal = readdir($ha))!==false)             
  {                             

   if(!is_dir($filelocal))  
   {  
     $fa[]=$filelocal;                                                          

   }
   sort($fa);
  }

  for($i=0;$i<sizeOf($fa);$i++)
  {    
       $pdfname=substr($fa[$i], 0, strpos($fa[$i], '.pdf')); 

       exec("convert -scale  1500x1000".$fa[$i]."D:/Images/ExtractFromFTP/img%d_".$pdfname.".png");

  }

In my code i am extracting multiple PDF'S, storing all extracted images into D:/Images/ExtractFromFTP/ at following path. so it is very hard to sort images as per it's pdf name. that's why i want to store extracted images into different different folders as per their pdf name to that folder(So it means i need to create folders run time) but i couldn't find the way of arrange order?

Kalashri
  • 17
  • 9

2 Answers2

0

I don't understand what your problem is. Have you tried to maybe Google your vague problem?

How to create a file

Link nr 2

Ruan
  • 3,969
  • 10
  • 60
  • 87
0

You can create directories with mkdir

$pdfname=substr($fa[$i], 0, strpos($fa[$i], '.pdf')); 
//you can also do this: 
$pdfname =  substr($fa[$i],0,-4); //this will cut off last for chars, eg '.pdf';

$dirname = "D:/Images/ExtractFromFTP/" . $pdfname;
if (mkdir($dirname)) {
    exec("convert -scale  1500x1000 " . escapeshellarg($fa[$i]) . escapeshellarg("D:/Images/ExtractFromFTP/${dirname}/img%d_".$pdfname.".png"));
} else {
     echo 'Could not create dir!';
}

So, the only thing you need to do is mkdir($directory); However, notice the escapeshellarg funcitons called to escape the pdf name and target png names. This is needed to ensure that the filenames with spaces are treated as one parameter and not as two, and to secure yourself if the names are invlaid.

SWilk
  • 3,261
  • 8
  • 30
  • 51