Reputation: 3938
I am trying to do something really simple with php but I can not find where I have the mistake! So, I want to echo an image like this (part of the code):
$file_path[0] = "/Applications/MAMP/htdocs/php_test/image_archive/".$last_file[0];
echo $file_path[0];
echo "<br>";
echo "<img src=\".$file_path[0].\" alt=\"error\">";
I must have some kind of error when I echo the img tag but I can not find it. Any help would be appreciated.
<div class="content">
<h1> Map</h1>
<?php
include '/Applications/MAMP/htdocs/php_test/web_application_functions/last_file.php';
$last_file = last_file();
$file_path[0] = "/Applications/MAMP/htdocs/php_test/image_archive/".$last_file[0];
echo $file_path[0];
echo "<br>";
echo '<img src="' . $file_path[0] . '" alt="error">';
?>
<!-- end .content --></div>
Upvotes: 0
Views: 66633
Reputation: 28409
echo "<img src=\".$file_path[0].\" alt=\"error\">";
is wrong
echo "<img src=\"".$file_path[0]."\" alt=\"error\">";
is what you think you're doing
It's useful to use single quotes so you don't make this mistake
echo '<img src="' . $file_path[0] . '" alt="error">';
Secondly
/Applications/MAMP/htdocs/php_test/image_archive/
looks like a path not a directory
Perhaps you mean
$file_path[0] = "/php_test/image_archive/".$last_file[0];
or
$file_path[0] = "image_archive/".$last_file[0];
Upvotes: 3
Reputation: 12581
You should use a path either relative to the server root, or the current file.
echo "<img src='/php_test/image_archive/" . $last_file[0] . "' alt='error'>";
Upvotes: 5