0

I have tried to image copy one directory to another directory but it is not working for me.

Here is my code:

<?php

$old_sub_dir = '/media/import';

$new_sub_dir = '/media/catalog/product/image';

//get directory contents
$contents = array();

$dir = opendir($_SERVER['DOCUMENT_ROOT'] . $old_sub_dir);

while (false !== ($file = readdir($dir))) {
       $contents[] = $file;
}
closedir($dir);

//get only jpeg contents
$jpeg_contents = array();

foreach($contents as $file){
    if (eregi('.jpg{1}$', $file)){
        $jpeg_contents[] = $file;
    }
}

// copy each jpeg from directory 'a' to directory 'b'
foreach($jpeg_contents as $file){
    copy($_SERVER['DOCUMENT_ROOT'] . $old_sub_dir . '/' . $file, $_SERVER['DOCUMENT_ROOT'] . $new_sub_dir . '/' . $file);
}

?>

and the error I'm getting is:

Uncaught Error: Call to undefined function eregi()

Any help would be appreciated.

Thanks.

Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79
Rakesh Donga
  • 135
  • 11
  • When you say it is not working - what is happening, if there are errors - please include them in your question. – Nigel Ren Jun 15 '19 at 07:12
  • @NigelRen i have try above code but not any image copy from this directory – Rakesh Donga Jun 15 '19 at 07:13
  • During the processing, you build a few arrays with the files you want to copy. Have you checked that these arrays have a list of the files your expecting?( Also you could do all the stages in 1 go, so not sure what you use 3 separate loops to process them). – Nigel Ren Jun 15 '19 at 07:15
  • i don't know how can use this but i have try array print but array is blank – Rakesh Donga Jun 15 '19 at 07:17
  • @NigelRen error is `Uncaught Error: Call to undefined function eregi()` – Rakesh Donga Jun 15 '19 at 07:26

1 Answers1

1

eregi() is depricated function from PHP version 5.3. Use preg_match() function istead.