Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6771655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:27:28+00:00 2026-05-26T15:27:28+00:00

I am using a simple script that displays images in a jquery slideshow –

  • 0

I am using a simple script that displays images in a jquery slideshow – these image filenames are listed in a .txt file, and change depending on the page you are on (im also using pagination in another script).

If the filename that is listed in the .txt file doesn’t exist, I would like the image ‘unavailable.jpg’ to display instead…

The original script:

<?php
echo"
<div id='slider-wrapper'><div id='slider' class='nivoSlider'>";
$photos=file("photos.txt");
foreach($photos as $image){
$item=explode("|",$image);
if($item[0]==$fields[0]){
$photo=trim($item[1]);
echo"<img src='images/work/$photo' alt='' />\n";
}
}
echo"
</div>
</div>
"?>

And here is my try at it…but it doesn’t work properly- instead of the ‘unavailable.jpg’ image being displayed, it shows all of the images in the directory… :S Anyone have any ideas of what I might be doing wrong? :S

<?php
echo"
<div id='slider-wrapper'><div id='slider' class='nivoSlider'>";
$photos=file("photos.txt");
foreach($photos as $image){
$item=explode("|",$image);
$photo=trim($item[1]);
if (file_exists("images/work/".$photo)) {
echo"<img src='images/work/$photo' alt='' />\n";
}
else{
echo"<img src='images/work/unavailable.jpg' alt='' />\n";
}
}
echo"
</div>
</div>
"?>

Instead of all the images showing, I only want images for that page to display. Here is an example of my text file:

1|image1.jpg
1|image2.jpg
1|image3.jpg
2|image1.jpg
2|image2.jpg

The 1 and 2 are for the pages 1 and 2, and they display the images that are listed. This all works fine in the above original script that I have posted, but it seems to break when I add the if file_exists.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:27:28+00:00Added an answer on May 26, 2026 at 3:27 pm

    The path to your images uses a relative path. Are you sure the current working directory is the directory you think it is?

    To verify do an echo 'Current Working Directory: '.getcwd()."<br />\n" and verify what directory you are in.

    Its probably best to use a full file path to your image’s directory so the script can be placed anywhere on your server.

    Now if that is correct then you need to check that your script has permission to your image directory. Typically php runs as nobody:nobody or apache:apache depending on your configuration.

    The directories above as well as the files should have 644 (-rw-r–r–) or at a minimum 444 permission (-r–r–r–).

    Try these two things and let us know if that solved your specific problem or not; I hope it does.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using jQuery to post a form to a php file, simple script to
I am using a simple live search script that displays the results from a
I have a simple php script on a server that's using fsockopen to connect
After loading a PHP template (using jQuery's load function), this simple script won't make
I am using one of snook.ca script for simple slideshow. Here it is in
I am writing a simple script that displays a dialog box when a user
I have a fairly simple page that displays an image in a pop-up window.
I have a simple drop-down menu that is controlled using the following script: $(document).ready(function
iam using a simple insert script function to pass the values from registration html
im using a simple test script from http://www.tuxradar.com/practicalphp/8/11/0 like this <?php $fp = fopen(foo.txt,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.