I am working on showing images via a database for a project with slimbox formatting, and am having issues with the mouse-over/hover-over caption. In the code I have
echo '<a href="images/' . $filename . '" rel="lightbox-set1"
title="' . $description.'<br>'."licence: ". $Licence. $Owner.'">';
echo '<img src="images-thumb/' . $filename . '" />';
echo '</a>';
and the mouse over caption for the image on screen shows:
The Lagoon in wellington<br>licence:free for all
I want to know if there is a way to remove the <br> from the caption displayed, without actually removing it, (<br>), from the code itself.
Change the <br> tag to a PHP line break PHP_EOL:
title="' . $description . PHP_EOL . 'licence: ' . $Licence . $Owner . '">';
This will insert a carriage return inside your title.
echo '<a href="images/' . $filename . '" rel="lightbox-set1"
title="' . $description.' '."licence: ". $Licence. $Owner.'">';
echo '<img src="images-thumb/' . $filename . '" />';
echo '</a>';
If you plan to have a new line when the user hovers to your image try this one
echo '<a href="images/' . $filename . '" rel="lightbox-set1"
title="' . $description.'
'."licence: ". $Licence. $Owner.'">';
Related
while trying to generate dynamic sitemaps, I tried adding two variables in url path, and the line is giving me error
this is my sample line:
echo "<loc>" . $base_url . "category.php?category=" . $subFeaturedPostCatSlug . "&job=" . "$subFeaturedPostSlug" . "</loc>" . PHP_EOL;PHP_EOL;
I tried doing it like this also:
echo "<loc>{$base_url}category.php?category={$subFeaturedPostCatSlug}&job={$subFeaturedPostSlug}</loc>" . PHP_EOL;
error screenshot attached;
Any help will be appreciated, thanks in advance
Try this -
$str = $base_url . "category.php?category=" . $subFeaturedPostCatSlug . "&job=" . $subFeaturedPostSlug . "" . PHP_EOL;
echo htmlspecialchars_decode($str);
You should be able to fix this using the urlencode() function as mentioned in your comments.
So,
echo "<loc>" . $base_url . "category.php?category=" . $subFeaturedPostCatSlug . "&job=" . "$subFeaturedPostSlug" . "</loc>" . PHP_EOL;PHP_EOL;
becomes
echo "<loc>" . urlencode($base_url) . "category.php?category=" . urlencode($subFeaturedPostCatSlug) . "&job=" . urlencode($subFeaturedPostSlug) . "</loc>" . PHP_EOL.PHP_EOL;
More details at PHP Documentation for urlencode()
Also, I found out that there is error in your code:
echo "<loc>" . $base_url . "category.php?category=" . $subFeaturedPostCatSlug . "&job=" . "$subFeaturedPostSlug" . "</loc>" . PHP_EOL;PHP_EOL;
Towards the end of the echo, you have written:
...PHP_EOL;PHP_EOL;
which should ideally have been
...PHP_EOL.PHP_EOL;
Hi I have security cam that uploads via ftp to my server and I want to show last images as slideshow but I can't manage it to work. I have this code
$base_path = 'wp-content/uploads/camer/10.121.0.202';
$latest_date_folder = scandir($base_path, SCANDIR_SORT_DESCENDING);
$latest_folder = scandir($base_path . "/" . $latest_date_folder[0], SCANDIR_SORT_DESCENDING);
$directory = '../" . $base_path . "/" . $latest_date_folder[0] . "/" . $latest_folder[0] . ';
try {
echo '<div id="myslides">';
foreach ( new DirectoryIterator($directory) as $item ) {
if ($item->isFile()) {
$path = $directory . '/' . $item;
echo '<img src="' . $path . '"/>';
}
}
echo '</div>';
}
catch(Exception $e) {
echo 'No images found for this slideshow.<br />';
}
?>
I am still getting 'No images found for this slideshow.'
But when I try this code
$latest1_date_folder = scandir($base1_path, SCANDIR_SORT_DESCENDING);
$latest1_folder = scandir($base1_path . "/" . $latest1_date_folder[0], SCANDIR_SORT_DESCENDING);
$latest1_file = scandir($base1_path . "/" . $latest1_date_folder[0] . "/" . $latest1_folder[0] , SCANDIR_SORT_DESCENDING);
echo "<img src='../" . $base1_path . "/" . $latest1_date_folder[0] . "/" . $latest1_folder[0] . "/" . $latest1_file[0] . "' />";
It displays last image normally. What am I doing wrong? Thanks a lot.
I am using wordpress plugin phpcode snippets
your directory variable is wrong!
you should write like this
$directory = '../'. $base_path . "/" . $latest_date_folder[0] . "/" . $latest_folder[0];
I am using the img tag but the code is in a php block.
<img class='client_image' src='" . get_stylesheet_directory() . "/assets/images/" . $print->client_images . "' alt='clientimage" . $clientindex . "' width='200' height ='200' />";
I keep getting not allowed to load local resource and I do not know why. I am using a premade wordpress theme. All I get is the broken image icon. The path is correct as well as the name of the file.
get_stylesheet_directory() will returns the path on your server, you need get_stylesheet_directory_uri() instead:
<img class='client_image' src='" . get_stylesheet_directory_uri() .
"/assets/images/" . $print->client_images . "' alt='clientimage" .
$clientindex . "' width='200' height ='200' />";
Attempting to print out an image to the browser using code I copied from http://php.net/manual/en/function.imagecopyresampled.php.
It prints out a box of random characters.
CODE:
public function printSummaryArticle($article, $copy, $thumb) {
$src_image = Config::getAbsPath() . '/images/articles/' . $article['image'];
echo
'<div class="summary_article"><a href="/'
. BreadCrumbs::getCrumb(1)
. '/'
. BreadCrumbs::getCrumb(2)
. '/article/'
. $article['id']
. '"><h4>'
. $article['title']
. '</h4></a> ('
. $article['date']
. ')'
. '<img src="data:image/jpeg;base64,'. imagejpeg($thumb->generateThumb($src_image, 300, 200)) . '"'
. '<p>'
. strip_tags($copy->truncateString($article['body'], 250, " "))
. '</p><p><a href="/' . BreadCrumbs::getCrumb(1)
. '/'
. BreadCrumbs::getCrumb(2)
. '/article/'
. $article['id']
. '"> Read more</a></p></div>';
}
Also tried:
public function printSummaryArticle($article, $copy, $thumb) {
$src_image = Config::getAbsPath() . '/images/articles/' . $article['image'];
echo
'<div class="summary_article"><a href="/'
. BreadCrumbs::getCrumb(1)
. '/'
. BreadCrumbs::getCrumb(2)
. '/article/'
. $article['id']
. '"><h4>'
. $article['title']
. '</h4></a> ('
. $article['date']
. ')';
header('Content-type: image/jpeg');
imagejpeg($thumb->generateThumb($src_image, 300, 200));
echo
'<p>'
. strip_tags($copy->truncateString($article['body'], 250, " "))
. '</p><p><a href="/' . BreadCrumbs::getCrumb(1)
. '/'
. BreadCrumbs::getCrumb(2)
. '/article/'
. $article['id']
. '"> Read more</a></p></div>';
}
Same result. except with an added error claiming headers have already been sent.
How can I fix this?
imagejpeg() neither returns a string nor performs Base64 encoding. To work around this, capture its output in a PHP output buffer, and then Base64 encode the captured output:
ob_start();
imagejpeg( $my_img );
echo '<img src="data:image/jpeg;base64,' . base64_encode(ob_get_clean()) . '">';
Note that data: URLs are limited to 32 KB in Internet Explorer 8 and do not work in earlier versions of IE (source). If you need to support IE 8 and below, you may want to instead save the image as a separate file on the server. This is left as an exercise for the reader :)
(For an explanation of the "Headers already sent" warning, see How to fix "Headers already sent" error in PHP.)
You haven't closed the image tag, but more importantly you haven't base64_encoded the image data
Before you echo that string
ob_start();
imagejpeg($thumb->generateThumb($src_image, 300, 200));
$imagejpg=ob_get_clean();
then this
. '<img src="data:image/jpeg;base64,'
. base64_encode($imagejpg)
. '" />'
You can't do what you're trying to do in the 2nd example
EDIT: Fixed, I had to remove all spaces I had (before the commas in the code below) and use trim
I'm trying to generate a CSV file using PHP. However the file splits into lines on its own. It looks fine in View Source, but excel/notepad show lines randomly broken up.
Here is my code :
// Echo Code Here
$string = '"REF1" , "FIRSTCLASS" ,"P" ,"1" ,"' . $orderref . '" ,"' . $fullname . '" ,"' . $add1 . '" ,"' . $add2 . '" ,"" ,"' . $postcode . '" ,"' . $city . '" ,"' . $country . '" ,"' . $fullname . '" ,"' . $telephone . '" ,"' . $email . '" ,"1" ,"1.0 kg"' . "\n";
echo $string;
Any help would be great, this is my first time working with CSV in PHP.
Since you're using Windows, you should use Windows-style line endings: \r\n instead of just \n.
There is PHP function forwriting CSV into file:
PHP "fputcsv" function
http://us2.php.net/manual/en/function.fputcsv.php