php - video file name doesn't load correctly

206

I'm new to PHP. Everything else works on my site okay but I seem to have an issue with this particular piece of code. The$efn is my file name, and I need to retrieve it from a MySQL database but this code doesn't seem to work. It works in a normal video container but not when using theif statement.

Any ideas how to fix this?

    <?php
$video_container = substr($efn, -3);
if ($video_container == 'mp4') {
    echo '<video preload="auto" width="640" height="264" poster="../images/<?php echo $thumb ?>" controls="controls" autoPlay="false">
<source src="<?php echo $efn ?>" type="video/mp4">
</video>';
}
else {
    echo '<video height="620" width="480" controls>
<source src="<?php echo $efn ?>" type ="video/avi" />
</video>';
}
?>
195

Answer

Solution:

You have syntax problem when printing the string. Replace the<?php echo $fn ?> section by' . $efn . '

Like this:

$video_container = substr($efn, -3);
if ($video_container == 'mp4') {
    echo '<video preload="auto" width="640" height="264" poster="../images/<?php echo $thumb ?>" controls="controls" autoPlay="false">
<source src="' . urlencode($efn)  . '" type="video/mp4">
</video>';
}
else {
    echo '<video height="620" width="480" controls>
<source src="' . urlencode($efn) . '" type ="video/avi" />
</video>';
}

People are also looking for solutions to the problem: php - Get selected value from CHtml::dropDownList

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.