Jump to content

JS/PHP slideshow basics don't work.


Rudovich

Recommended Posts

Hello everyone,

 

I am trying to create a simple slideshow to learn javascript and a small amount of PHP. People are meant to simply upload a photo to their site using for example Filezilla. The website should automaticly take the photo into the slideshow.

 

I am still very novice though.

 

So far I got:

+ PHP to read the file names in the folder.

+ Javascript to take over the PHP Array.

 

That is not much.. but I already run into a mistake in the next part.

 

<?php            $PhotoSlideAll = scandir('./photos');            $PhotoSlide = array_diff($PhotoSlideAll, array('.', '..'));?>
<script>            var SlideShow = ["<?php echo join("", "", $PhotoSlide); ?>"];            var SSl=SlideShow.length - 1;            var picture = "'../photos/" + SlideShow[0] + "'"            document.getElementById("backgroundswitch").style.backgroundImage = "url(picture)";</script>

Now somehow, it doesn't actually change the background. Whilst the variable picture is really '../photos/PHOTONAME.jpg' when I use an Alert to test it.

 

Edit: Thank you in advance ;)

Edited by Rudovich
Link to comment
Share on other sites

what is this line supposed to be doing?

 

document.getElementById("backgroundswitch").style.backgroundImage = "url(picture)";

 

why just set it to picture? you are setting it to a string with the value of url(picture)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...