0

I am writing php code in an html. Now I get a parse error which I am not able to trace!Could somebody help me fix it

echo '<a href="'.base_url('uploads/files/'.$file['file_name']).'">
  <img src="echo base_url('uploads/files/'.$file['file_name'])">
  <p>Uploaded On '.date("j M Y",strtotime($file['created'])).'</p>';

Error:-Parse error: syntax error, unexpected 'uploads' (T_STRING), expecting ',' or ';'

Celin Matthews
  • 61
  • 1
  • 3
  • 11
  • Second line, drop `echo` and replcae it with `'.` - then you'll need `.'` before `">` at the end on that line. Look at the syntax highlighting here on SO (or use a proper editor), and look at how you already concat strings together. – Qirel Apr 27 '17 at 12:44
  • Look at this point `src="echo base_url` – JustOnUnderMillions Apr 27 '17 at 12:44

3 Answers3

0
echo '<a href="'.base_url('uploads/files/'.$file['file_name']).'">
  <img src="'.base_url('uploads/files/'.$file['file_name']).'">
  <p>Uploaded On '.date("j M Y",strtotime($file['created'])).'</p>';
aprogrammer
  • 1,764
  • 1
  • 10
  • 20
  • 1
    Why the down vote on this answer? – RiggsFolly Apr 27 '17 at 12:48
  • Whilst this code snippet is welcome, and may provide some help, it would be [greatly improved if it included an explanation](//meta.stackexchange.com/q/114762) of *how* it addresses the question. Without that, your answer has much less educational value - remember that you are answering the question for readers in the future, not just the person asking now! Please [edit] your answer to add explanation, and give an indication of what limitations and assumptions apply. – Toby Speight Apr 27 '17 at 14:49
0

Step by step

$bu = base_url('uploads/files/'.$file['file_name']);
$d = date("j M Y",strtotime($file['created']));
echo '<a href="'.$bu.'"><img src="'.$bu.'"/><p>Uploaded On '.$d.'</p></a>';

to prevent typos and syntax errors

Note: added an missing </a>

JustOnUnderMillions
  • 3,741
  • 9
  • 12
-1

Make a var like this :

$linkToImg = base_url('uploads/files/'.$file['file_name']);
$uploadDate = date('j M Y',strtotime($file['created']));

echo "<a href='". $linkToImg ."'>";
echo "<img src='". $linkToImg ."'>";
echo "<p>Uploaded On ". $uploadDate ."</p>";
echo "</a>"; // Don't forget to close <a> tag
Cyril Beeckman
  • 1,248
  • 10
  • 24