php - copy files from directory to destination recursively -
i wrote php script copy images directory "oldphoto", , rename , move them example logo.png -> directory /l/o/logo.php
but directory created, images not copied, following code
<?php $objects = scandir('./oldphoto'); foreach ($objects $value) { if ($value!='.' && $value!='..') { $prefix = renametxt($value); moveimg ($prefix, $value); } } function renametxt ($line) { $first_char = '/'.substr($line, 0 ,1); $sec_char = '/'.substr($line, 1 ,1).'/'; $prefix = $first_char.$sec_char; return $prefix; } function moveimg ($prefix, $filename) { $src = $filename; $dst = '/newphoto'.$prefix; rcopy('oldphoto/'.$src, $dst, $filename); } function rcopy($src, $dst, $filename) { @mkdir('newphoto/'.$dst, 0, true); //echo $dst."<br>"; echo $dst.$filename."<br>"; echo 'src '.$src."<br>"; echo 'filename '.$filename."<br>"; if (!copy($src, $dst.$filename)) { echo "fail write image"; } } ?>
any 1 can figure out problems?
echo results:
/newphoto/l/o/logo.png src oldphoto/logo.png /newphoto/l/o/logo_mini.png src oldphoto/logo_mini.png /newphoto/w/h/white50.png src oldphoto/white50.png
your destination wrong. slash @ beginning causes in root directory not directory. either use dir or specify directory absolute path.
Comments
Post a Comment