Need PHP Expert Help

jeffr0

Regular Member
Joined
Sep 1, 2019
Messages
321
Reaction score
191
Hello, I have a php function that grabs video thumbnails. I need the code edited to where if there is no thumbnail in that directory it grabs it from a secondary base URL.

So basically IF BASE_URL/media/videos/file.jpg == NULL, then grab from BASE_URL2/media/videos/file.jpg

Can anyone help? Willing to give a small cash reward if someone can help with this quickly, thanks

https://pastebin.com/Pj80jajF
 
Hello, I have a php function that grabs video thumbnails. I need the code edited to where if there is no thumbnail in that directory it grabs it from a secondary base URL.

So basically IF BASE_URL/media/videos/file.jpg == NULL, then grab from BASE_URL2/media/videos/file.jpg

Can anyone help? Willing to give a small cash reward if someone can help with this quickly, thanks

https://pastebin.com/Pj80jajF
<?php
function getVideoThumbnail($filename) {
// Define the base URLs
$primaryBaseUrl = 'BASE_URL/media/videos/';
$secondaryBaseUrl = 'BASE_URL2/media/videos/';

// Define the full paths
$primaryFilePath = $primaryBaseUrl . $filename;
$secondaryFilePath = $secondaryBaseUrl . $filename;

// Check if the file exists at the primary location
if (file_exists($_SERVER['DOCUMENT_ROOT'] . $primaryFilePath)) {
// If the file exists, return the primary file path
return $primaryFilePath;
} else {
// If the file doesn't exist, return the secondary file path
return $secondaryFilePath;
}
}

// Example usage
$thumbnail = getVideoThumbnail('file.jpg');
echo '<img src="' . $thumbnail . '" alt="Video Thumbnail">';
?>
 
as past PHP expert, I would highly recommend to not use this language in any production environment.
 
as past PHP expert, I would highly recommend to not use this language in any production environment.
not sure how long ago your "expert" state is, but, PHP has come along way.
Most recent versions have everything needed. Of course, legacy projects suck. What language are you using now?
But sure, wordpress & laravel did not help the image of PHP. Sure laravel made it popular again, but what they consider "artisan" code, is ridiculous.

And just to be frank, i am highly suspicious of people claiming to be experts in a language without proof they've contributed to the language itself. I am doing this for almost two decades now professionally. I have done almost every mistake you can think of and built so many different things from scratch... i know others consider me an expert, and if someone asks my rate, of course i am an expert. But to be honest, i am still baffled by the confidence of people claiming they're senior after 5 years. And even more so, how fast they get humbled when working with people who really like to get shit done the right way.

---

EDIT: now that i have looked at the code, i must admit, i understand your sentiment. I'd join you on saying: don't run the code of the person who wrote this initially on prod.
The nice thing about PHP is the ease of getting started. Which of course leads to the bad reputation: anyone can start, so anyone will. Hence, so much bad PHP code all around is. But like i said, modern PHP is almost like a different language. I could name many more things, but I doubt anyone here cares, so i stop.
As with everything: try to do it right, or find someone who will. Otherwise, don't waste potential.
 
Hello, I have a php function that grabs video thumbnails. I need the code edited to where if there is no thumbnail in that directory it grabs it from a secondary base URL.

So basically IF BASE_URL/media/videos/file.jpg == NULL, then grab from BASE_URL2/media/videos/file.jpg

Can anyone help? Willing to give a small cash reward if someone can help with this quickly, thanks

https://pastebin.com/Pj80jajF
Replace your get_thumb_dir($vid) function with this

PHP:
function get_thumb_dir($vid)
 
{               
 
    global $config;
 
 
 
    $index = intval( ($vid - 1) / $config['max_thumb_folders'] );
 
    $tmb_folder = 'tmb';
 
    if ($index !== 0) {
 
        $tmb_folder = 'tmb'.$index;
 
    }
 
    $path = $config['BASE_DIR'].'/media/videos/'.$tmb_folder;
 
 
 
    if (!file_exists($path)) {
 
        $path = $basedirectory2.'/media/videos/'.$tmb_folder;
 
    }   
 
 
 
    $output = $path.'/'.$vid;
 
 
 
    return $output;
 
}
then replace the $basedirectory2 with 'secondary base directory url'
 
Back
Top