heres my error msg

0006II_1.MXF
Warning: copy(Array) [function.copy]: failed to open stream: No such file or directory in C:\Program Files\xampp\htdocs\ripper\process.php on line 26
failed to copy Array...

in and process are folders and in the root of the php script that is running.

Any thoughts?????????

heres my code

<?php

foreach($_POST['checkbox'] as $value)

{

$file[] = '\in\$value';
$newfile[] = '\process\$value';



if (!copy($file, $newfile)) {
echo "failed to copy $file...\n";
} 

}

?>

    Your issue is that you're creating an array with the variable $file by using the [] after the variable name. This will automatically add an array element, or create an array if it isn't one already.

    Three options:
    1.) Simplist:
    [indent]Remove the "[]" after $file, and $newfile and everything should work fine. Then you're just using the variables as such, and not arrays.[/indent]
    2.) More of what you want:
    [indent]Remove the if(){} statement from the foreach() loop. When you're done, then run an itterative for() loop while $i is less than total number of elements in $files. Then do your copy() items on $file[$i].[/indent]
    3.) Most likely the best:
    [indent]Change your code slightly so that you add two lines:

    $t_file = '\in\'.$value;
    $t_newfile = '\process\'.$value;

    Then, in the if statement, change $file to $t_file and $newfile to $t_newfile.[/indent]

    Right now, even if you weren't using arrays, your code is still incorrect as the value of $value wouldn't be parsed. So you'd have an array of the same value: \in\$value[\b], literally. You'd need to use double quotes: " or concatenate the string if you want to use single quotes: '. Also, watch your backslashes. They double as escapes. Typically, it's best to use forward slashes (Windows can translate as needed).

    Here's the best way to do it (in my opinion):

    <?php
    
    foreach($_POST['checkbox'] as $value)
    {
      $t_file = '\in\\'.$value;
      $file[] = '\in\\'.$value; // Gotta concatenate with single quotes
    
      $t_newfile = '\process\\'.$value;
      $newfile[] = "\process\\$value"; // Or use double quotes to allow PHP to parse variables
    
      if (!copy($t_file, $t_newfile)) {
        echo "failed to copy $file...\n";
      }
    }
    
    ?>

      thankyou for such an excellent reply and explaining exaclty how it works...I now have working code (for this bit anyways) thanks to you.

      Cheers

      Neil

        Write a Reply...