Jump to content

[SOLVED] Shouldn't this be easy???


networkthis

Recommended Posts

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

<?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'];
?>

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.

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

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.