pugboy Posted June 8, 2008 Share Posted June 8, 2008 I have absolutely no clue why this file is not copying into an existing directory... My file tree is below: htdocs -beta --account ---admin --usercp ---add.php ---index.php --template ---home ----index.html ----login.php ----files.txt If you can understand it, it shows that I need index.php to copy everything from the home template folder over to account>admin (or another user) So far, it creates the directory. However, it does not copy the files. It outputs the message below: Checking files... Files Intact... Copying files... Creating directory: ../account/admin/home Directory Created. Template Exists... Copying Files...Failed to copy ../template/home/index.html to ../account/admin/home/index.html I have done everything to look for errors, and pinpoint a problem. I have found nothing running my code through php Design Studio, and numerous online syntax checkers... My code: if($do=="add"){ echo "Checking files...<br/>"; $baseDir = "../account/" . $user; $dir = "../account/" . $user . "/" . $type; $dirTemplate = "../template/" . $type; $fileList = $dirTemplate . "/files.txt"; $passwords = md5($user); $passwords = $passwords . ".txt"; $indexfile = $dirTemplate . "/index.html"; echo "Files Intact... Copying files... <br/>"; echo "Creating directory: $dir<br/>"; if(!mkdir($dir)){ echo "Fatal Error. Directory did not create"; exit; } else { echo "Directory Created.<br/>"; } $fileName = $fileList; $fh = fopen($fileName, 'r'); $fileListB = fread($fh, filesize($fileName)); fclose($fh); $fileListC = explode("\n",$fileListB); echo "Template Exists... Copying Files..."; for ( $id = 0; $id <= $maxid; $id += 1) { $fileT = $dirTemplate . "/" . $fileListC[$id]; $fileD = $dir . "/" . $fileListC[$id]; if(!copy($fileT, $fileD)){ echo "Failed to copy $fileT to $fileD"; exit; } else { echo "Copy file: $fileT. Success!"; } } } $do = $_GET["do"] fyi... Does ANYONE see ANYTHING wrong, or is the code hopeless? Quote Link to comment Share on other sites More sharing options...
pugboy Posted June 8, 2008 Author Share Posted June 8, 2008 Sorry to bump, but I need this sometime today :-\ Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 8, 2008 Share Posted June 8, 2008 Are you sure the home directory in account/admin has the correct permissions for writing files? EDIT: I have modified your code slightly: if($do=="add") { echo "Checking files...<br/>"; $baseDir = '../account/' . $user; $dir = $baseDir . $user . '/' . $type; $dirTemplate = "../template/" . $type; $fileList = $dirTemplate . "/files.txt"; $passwords = md5($user); $passwords = $passwords . ".txt"; $indexfile = $dirTemplate . "/index.html"; echo "Files Intact... Copying files... <br/>"; echo "Creating directory: $dir<br/>"; if(!mkdir($dir)) { echo "Fatal Error. Directory did not create"; exit; } else { echo "Directory Created.<br/>"; } echo "Template Exists... Copying Files...<br />"; $fileList = file($fileList); foreach($filesList as $file) { $sourceFile = $dirTemplate . '/' . trim($file); $targetDest = $dir . '/' . trim($file); if(is_writable($dir)) { if(!copy($sourceFile, $targetDest)) { echo "<br />Failed to copy $fileT to $fileD"; exit; } else { echo "Copy file: $fileT. Success!"; } } else { exit($dir . ' is not writable! Unable to copy files!'); } } } Quote Link to comment Share on other sites More sharing options...
webent Posted June 8, 2008 Share Posted June 8, 2008 Yeah, like he said, check the chown and chmod properties of the created directory... see what they are... maybe that's why it isn't being moved into it... Quote Link to comment Share on other sites More sharing options...
pugboy Posted June 8, 2008 Author Share Posted June 8, 2008 Every folder and file is chmoded to 777, so that can't be it. I will try your code now. The for loop does not seem to be executing at all... Other than that, it works. Quote Link to comment Share on other sites More sharing options...
pugboy Posted June 9, 2008 Author Share Posted June 9, 2008 Ok then.... I rewrote the copy funtion, BUT IT STILL FAILS! Here is my new code: if($do=="add"){ $type = $_POST["type"]; echo "Creating account for $user<br/>"; $tDir = "../template/" . $type; $dDir = "../account/" . $user . "/" . $type; $pFileName = $dDir . "/" . md5($user) . ".txt"; if(!mkdir($dDir)){ echo "Directory did not create. Aborting"; exit; } $fList = $tDir . "/files.txt"; $fileList = file($fList); foreach( $fileList as $id => $name){ $tFileN = $tDir . "/" . $name; $dFileN = $dDir . "/" . $name; if(!copy($tFileN,$dFileN)){ echo "Transfer of $tFileN to $dFileN failed. Aborting"; exit; } } } I KNOW the copy function works outside of a for loop.... I just created a test function that succeeded! Is this a PHP limitation? EDIT: Fails in a while loop as well. Quote Link to comment Share on other sites More sharing options...
pugboy Posted June 9, 2008 Author Share Posted June 9, 2008 I wish you guys allowed an unlimited time to edit... It must have to do with the string... I was able to copy a file when I used strings as parameters, and not variables... Quote Link to comment Share on other sites More sharing options...
pugboy Posted June 9, 2008 Author Share Posted June 9, 2008 Turns out there were extra spaces. A substring solved that easily. Quote Link to comment 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.