Jump to content
Rudovich

JS/PHP slideshow basics don't work.

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

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...