Jump to content

copy Folder files and SubFolder


p9j

Recommended Posts

hi all,

 

i have this music website and i have to upload every album under this folder "newsongs" ... in AlbumName folder i have normal quilty songs and HQ folder..under HQ folder i have High Quilty songs for each album.

 

 

i have this coding which moves Album folder  and normal quilty songs to other folder "songs" but i also want to move subfolder "HQ" and High Quilty songs with AlbumName  folder

 

 

 

for($i=0;$i<=$ct;$i++)
{
$alb=$alname[$i];
$cat=$catname[$i];
$albids=$albid[$i];
$fon=$folder_name[$i];

$tmp_name=$doc_root."newsongs/$fon";
$uploads_dir=$doc_root."songs/$cat/$fon";

if ($handle = opendir($tmp_name)) {
	/* This is the correct way to loop over the directory. */ 
	while (false !== ($file = readdir($handle))) {
		//echo "$file\n <br>";
		if($file !=='..' and $file !=='.')
		{
		$song_path="songs/$cat/$fon/$file";
			if(!is_dir("$tmp_name/$file") and (!is_dir("$uploads_dir/$file")))
			{
				if(copy("$tmp_name/$file", "$uploads_dir/$file"))
				{
				$cp=1;
				$ext=substr($file,-4);
					if($ext=='.mp3')
					$insqry=mysql_query(" insert into tbl_songs set song_name='$file', album_id='$albids', artist_id='$artid', song_path='$song_path' ");

				unlink($tmp_name.'/'.$file);
				}
				else
				{
				echo "could not move songs ";
				}
			}
		}
			if($insqry)
			  $msg="songs Added to the database";
			else
			$msg="songs Not Added to the database";
	}
	closedir($handle);

 

thnx in advnce 8)

Link to comment
https://forums.phpfreaks.com/topic/247485-copy-folder-files-and-subfolder/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.