PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am trying to create a thumbnails and captions "gallery" (no large images like in a traditional gallery, just the thumbs/captions) which draws the thumbnails and the captions from directories on the server.
The images show up as expected.
I would like to read a number of text files from another directory (I do not want to hardcode the file names) next to the images.
Warning: fopen() expects parameter 1 to be string, array given in ... line 28
Warning: fgets(): supplied argument is not a valid stream resource in .... line 29
That is not all of your code and that fopen() is not from line 28.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
#1 You're reusing $i and $files in the nested loop, so it will reset it for the outer loop. Change it to $j and $captions maybe. #2 You did it correctly for the images, so do this for the captions:
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
AbraCadaver wrote:#1 You're reusing $i and $files in the nested loop, so it will reset it for the outer loop. Change it to $j and $captions maybe. #2 You did it correctly for the images, so do this for the captions:
foreach (glob("captions/*.*") as $file) {
echo file_get_contents($file);
}
Depending upon what you want.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
I would like for each image to have its own caption. ex: image1/caption1, image2/caption2, etc...
Does that make any sense?
Does each caption file only contain 1 caption? If so, how does the image file relate to the caption file, by the number 1,2,3, etc.? If not, then it is very confusing.
This may be a flawed design that needs to be done a different way.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Right now the images and captions aren't related through their names, but I can make them so (haven't created all the images yet).
I need the images and captions to be fetched from directories, because later on I will need to refer to them from different pages, and galleries. I don't want to have to update the same images on different pages.
I've tried every image gallery on the web (I think), and can't find a solution. Any ideas?
foreach(glob("images/*.*") as $image) {
foreach (glob("captions/$image/*.*") as $caption) {
echo file_get_contents($caption);
}
echo '<li><img src="'.$image.'" alt="random image"><div>something here'.'</div></li>'." ";
}
Now, in images/ you would have image1.jpg, testimage.png, etc.. and in captions/ you would have subdirs image1.jpg/, testimage.png/, etc.. that contain the caption files.
This is just a simple example that may not be scalable.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.