1

I have this code:

   $path = "./wp-content/uploads/webvideos/";
$webdir = site_url()."/wp-content/uploads/webvideos/";
$post_title = html_entity_decode(get_the_title());


$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS));
$files = array();
$notAllowedExtension = array('jpg', 'mp3', 'vtr', 'html', 'htm' );

foreach($iterator as $file){



if(!in_array($file->getExtension(), $notAllowedExtension) && !$file->isDir())
    $files[] = $file->getFilename();

}


ksort($files);

foreach($files as $value){
    Echo $value . "<br>";
}



if( $autoplay > count( $files ) ) $autoplay = 1;

if( $autoplay > 0 ) $autoplay = $autoplay -1;

foreach($files as $file => $date){
if(  $i==$autoplay ) $file_main = $file;
$output .= "" . PHP_EOL .
 "<tr>
     <td><a href=\"javascript:loadVideo('$webdir$file.mp4')\"> $file - (Click Me)</a>
</td>
    <td>NA</td>     

  </tr>"
. PHP_EOL;
$i++;
}

I have added more of the code. Now I have an issue because the echo works but not the rest of the code.

However, the output is:

[1350528689] => V001 - Test Video.mp4
[1350568321] => V001-Test-Video.mp4
[1430061765] => V001-My-First-Video.mp4

But I need it to be like this:

V001 - Test Video.mp4
V001-Test-Video.mp4
V001-My-First-Video.mp4

I have spent hours looking for a solution, but not joy.

2 Answers 2

2

Try this:

if(!in_array($file->getExtension(), $notAllowedExtension) && !$file->isDir())
    $files[] = $file->getFilename();

}

Edit: but this will not remove the key. It will make it 0, 1, 2 etc.
I'm quite sure you can't have an array without keys.

Or is the question how to print the files without the keys?

Edit ok.. so you need to print them without keys.

foreach($files as $value){
    Echo $value . "<br>\n";
}
Sign up to request clarification or add additional context in comments.

7 Comments

Not quite, it comes up like so: [0] => V001 - Test Video.mp4 [1] => V001-Test-Video.mp4 [1] => V001-My-First-Video.mp4 I also recall trying this as well.
Print_r and var_dump are used to see how an array is set up. What you need is to echo the array values
@Arthor got it working? The last part is the only thing you need. The foreach... and it should replace your code: echo "<pre>" . print_r($files, true) . "</pre>";
I have updated the code, the echo work perfectly HOWEVER, the rest of the code only show the key. How would I get the output of the echo to be the same through the rest of the code. Thanks
Maybe you need the keyvalue as it was. Reset the part where $file[this part]= to what it was and maybe it works. It should. But I can't guarrantee it.
|
1
$title=$files[$file]; 
 if( $i==$autoplay ) $file_main = $file; 
 $output .= "" . PHP_EOL . 
 "<tr> 
 <td><a href=\"javascript:loadVideo('$webdir$file.mp4')\"> $file - $title(Click Me)</a>

The final answer is this.

11 Comments

It does work outputting with echo however the rest of the $files as the key index, not the value.
Can you explain better doing some examples? Thanks P.S. I have based my answer on your output
Please echo the $file variables. In the meanwhile, If I understood correctly, try to echo in that foreach $files[$value][1] and see what happen
print_r($files) to see the structure of your $files so I can reach directly the title of your video. Please note that you have missed a "s" in $file
Please confirm the answer to show the post as solved
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.