networkthis Posted June 2, 2008 Share Posted June 2, 2008 I am simply trying to count the number of files that are being copied in this output, I would like to count the number of files that were copied correctly. <?php if($copy){ echo "<tr><td width=\"175\"> $file</td> <td> Yes</td><tr>"; }else{ echo "<tr><td width=\"175\"> $file</td> <td> No</td><tr>"; } I have been trying this for a while and it never comes out correct. Any ideas? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/108334-solved-shouldnt-this-be-easy/ Share on other sites More sharing options...
rajug Posted June 2, 2008 Share Posted June 2, 2008 I think you have to show the code that is copying the files to see the problem. I guess you are looping through the reading a directory. So better show the copying code and what the variable $copy is holding/getting. Link to comment https://forums.phpfreaks.com/topic/108334-solved-shouldnt-this-be-easy/#findComment-555409 Share on other sites More sharing options...
networkthis Posted June 2, 2008 Author Share Posted June 2, 2008 <?php $number_uploads = $_POST['number_uploads']; // start for loop for($x=0;$x<$number_uploads;$x++){ //The path for where the file will be uploaded to $target = ("NewFolder//" . trim($_SESSION["first_name"],"~!@#$%^&*()+`-={}|[]\:;<>?,./") . $slash); //Adds the input from the form to the beginning of the uploaded file name $target = $target . trim($_SESSION["first_name"],"~!@#$%^&*()+`-={}|[]\:;<>?,./") . '_' . basename( $_FILES['file_upload'. $x]['name']); $copy = copy ($_FILES['file_upload'. $x]['tmp_name'], $target); // check if successfully copied $file = $_FILES['file_upload'. $x]['name']; ?> Link to comment https://forums.phpfreaks.com/topic/108334-solved-shouldnt-this-be-easy/#findComment-555411 Share on other sites More sharing options...
haku Posted June 2, 2008 Share Posted June 2, 2008 Change this: for($x=0;$x<$number_uploads;$x++){ //The path for where the file will be uploaded to $target = ("NewFolder//" . trim($_SESSION["first_name"],"~!@#$%^&*()+`-={}|[]\:;<>?,./") . $slash); //Adds the input from the form to the beginning of the uploaded file name $target = $target . trim($_SESSION["first_name"],"~!@#$%^&*()+`-={}|[]\:;<>?,./") . '_' . basename( $_FILES['file_upload'. $x]['name']); $copy = copy ($_FILES['file_upload'. $x]['tmp_name'], $target); to this: $y = 0; for($x=0;$x<$number_uploads;$x++){ //The path for where the file will be uploaded to $target = ("NewFolder//" . trim($_SESSION["first_name"],"~!@#$%^&*()+`-={}|[]\:;<>?,./") . $slash); //Adds the input from the form to the beginning of the uploaded file name $target = $target . trim($_SESSION["first_name"],"~!@#$%^&*()+`-={}|[]\:;<>?,./") . '_' . basename( $_FILES['file_upload'. $x]['name']); if(copy ($_FILES['file_upload'. $x]['tmp_name'], $target)) { $copy = true; $y++; } else { $copy = false; } And after all the files have been gone through, $y will be equal to the number of successfully copied files. Link to comment https://forums.phpfreaks.com/topic/108334-solved-shouldnt-this-be-easy/#findComment-555419 Share on other sites More sharing options...
networkthis Posted June 2, 2008 Author Share Posted June 2, 2008 Thanks for the input...I don't know how I overlooked something so simple!!!! Thanks for the help I ended up simply adding this after viewing your suggestion. <?php if($copy==TRUE) { $y++; } ?> I kept all the rest of the code intact.. just simply added the $y variable to do the counting of the copied files. Thanks again Link to comment https://forums.phpfreaks.com/topic/108334-solved-shouldnt-this-be-easy/#findComment-555430 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.