0

I'm trying to update an old flash gallery site of mine using php. I'm wondering how I can get a file name randomly from the folder that stores all of the flashs after the original flash has been middle mouse clicked. I'm new to php and I feel as if I have some things mixed up and I have gaps in my knowledge.

HTML

<?php include 'header.php'; ?>

<div id="flash-container">
    <object id="flash-content" data="swfs/sunshine.swf" type="application/x-shockwave-flash"></object>
    </div>

<?php include 'footer.php'; ?>

PHP

<?php
function random_flash($dir = 'swfs')
{
    $files = glob($dir . '/*.*');
    $file = array_rand($files);
    return $files[$file];
}
?>

Javascript

$(document).ready(function () {
    $("#flash-content").on('click', function (e) {
        $.ajax({
            type: "GET"
            , url: "flash.php"
            , data: {
                fileName: "$file"
            }
        }).done(function (msg) {
            alert("Data Saved: " + msg);
        });
        if (e.which == 2) {
            e.preventDefault();
            flash - container.innerHTML = '<object id="flashcontent" data="' + $file + '">' + '<param name="movie" type="application/x-shockwave-flash">' + '</object>';
        }
    });
});
3
  • So what exactly is the problem? Commented Oct 24, 2016 at 21:36
  • When I middle click on the existing flash object it should look into the 'swfs' folder and randomly select a name when the name is selected it should change the innerHTML of the flash itself to insert the file name so to go to the next flash Commented Oct 24, 2016 at 21:39
  • Maybe I shouldn't use javascript at all with the name insertion and I should just use php for it...... Commented Oct 24, 2016 at 21:40

1 Answer 1

1

I think there are some error on your code.

If you call php, even in a javascript code ... you need to use <?php and ?>.

On your javascript code, I can see $file. Okay, but what is it ? Should be <?php echo $file; ?> no ?

And in your JS code : flash - container.innerHTML What is the object flash ? You can't substract object like this :) (Typo error ?)


So:

  1. On your html web page randered, open the Console Editor and check if tehre is any error.
  2. Open the source code of the page and check if the html/javascript seems good. If you are php error -> check the php code.

You can also and somewhere a <?php echo $file; ?> or <?php echo random_flash(); ?> to check if the value return is a file and the expected value.

Sign up to request clarification or add additional context in comments.

Comments

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.