countdrac Posted November 2, 2008 Share Posted November 2, 2008 hi i need to write an application that takes all the files in a directory, move them, and add the information to a DB based on where the files were uploaded to. eg. upload/name1/category2/file.ext needs to move to main/name1/category2/file.ext but the name1, category2 and file.ext all need to be added to a database. im not sure of the best way to do this. im sure there must be a better way to get information from the directories and files then the way i have it at the moment. also if the decide to change how many directories they will be using its a bit of a mess at the moment. at the moment ive got: function listdirs($dir) { static $alldirs = array(); $dirs = glob($dir . '/*', GLOB_ONLYDIR); if (count($dirs) > 0) { foreach ($dirs as $d) $alldirs[] = $d; } foreach ($dirs as $dir) listdirs($dir); return $alldirs; } $dirs = listdirs('../audioUpload'); array_unshift($dirs, "../audioUpload"); foreach($dirs as $dir) foreach (glob($dir."/*.mp3") as $file) { $fileName = split("/*/",$file); $num = count($fileName); echo "<option value='".$file."'>.."; for ($i=2;$i<$num;$i++) echo "/".$fileName[$i]; echo "</option>"; } $file = $_POST['fileID']; $fileName = split("/",$file); $num=count($fileName); $dir = "../audioMain/".$speaker; if(!file_exists($dir)) { if(mkdir($dir,777)) { $dir = "../audioMain/".$speaker."/".$category; if(mkdir($dir,777)) {}else echo"error"; } } else { $dir = "../audioMain/".$speaker."/".$category; if(!file_exists($dir)) if(mkdir($dir,777)) {}else echo"error"; } $newFile = $fileName[0]."/audioMain/".$speaker."/".$category."/".$fileName[$num-1]; $setPath = "../audioMain/".$speaker."/".$category."/"; $query = "INSERT INTO ... .. '".$fileName[0]."/audioMain/".$speaker."/".$category."/', '".$fileName[$num-1]."' if(rename($_POST['fileID'], $fileName[0]."/audioMain/".$speaker."/".$category."/".$fileName[$num-1])) { $dirCheck = $_POST['fileID']; $dir = $dirCheck; $check=split("/",$dirCheck); $numDirs = count($check); for($i=2;$i<$numDirs;$i++) { $dirDel = split($check[$i],$dir); if(is_emtpy_dir($dirDel[0])) { if(rmdir($dirDel[0])) { // echo "DELETED FOLDER: <br />"; } } } } thanks Quote Link to comment https://forums.phpfreaks.com/topic/131075-file-maniplulation/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.