-1

I have a pretty simple webpage that contains an embedded video where the page author manually sets $variables at the top of document to set the correct video/photo/title/links, etc. within the "html code" further down the page (for non-expert users to upload and link new content to the template). It's not the prettiest code but it works. (yay!)

In one place, they need to be able to point a variable to a specific video file, OR upload several files into a new directory and point/transform the variable into an include that runs a randomizer php file. I SHOULD CLARIFY THAT THE RANDOMIZING FUNCTION ALREADY WORKS, I just need to be able to point to it with a $variable

$video1sourcedir = '/documents/sword.mov';
//needs to create
<video src="/documents/sword.mov" width="400" height="225" controls autoplay loop preload>

or (I wish) they could change it to something like

$video1sourcedir = '<?php include "randvid.php';
//but I can't nest php with echo so that doesn't actually create
<video src="<?php include "randvid.php"; ?>" width="400" height="225" controls autoplay loop preload>

So basically does anyone know a way to set $variables at the top of the page that can be called that way? It would be ok for the $variable to be the entire php include statement but I don't know how to echo or print that correctly

Much thanks!

Rasclatt
  • 12,498
  • 3
  • 25
  • 33
teame
  • 1
  • 6
  • take a look at this for a function on selecting a random file from a directory: http://stackoverflow.com/questions/4478783/select-random-file-from-directory – Clay Sep 24 '15 at 02:01
  • For images I used the same external randomizing script and got it to work like so: $mainimage = 'steel.jpg '; etc. and "width="600">... but that doesn't work with video files for some unknown reason – teame Sep 24 '15 at 02:01
  • Also to clarify these are NON-EXPERT VOLUNTEERS editing and uploading new "text" files directly the the server, not web-users passing data through forms etc., so i need to make it as simple as possible, also I'm not a php expert so I will have alot of trouble re-engineering the process... every little edit breaks something on this delicate little beast of a site! – teame Sep 24 '15 at 02:05
  • What does `randvid.php` do? Or what is it supposed to do rather? – Zsw Sep 24 '15 at 02:05
  • I have a randomizer already working, (currently a php include)... but when utilizing the template they often will need to link to a specific .mov file., and I want to place that variable with the rest (there is a list of variables that corresponds to the images, galleries, and movies they can edit at the top of the template page) For images I used the same external – teame Sep 24 '15 at 02:08
  • randvid.php is a currently existing php that is working. You can see an example of the site at www.teamezazzu.com – teame Sep 24 '15 at 02:09
  • So basically the volunteers can edit something like this rather than wade through all the code (that way they can concentrate on uploading clips and photos to directories)$pagetitle = 'Teame Zazzu'; $bodybackgroundimage = 'siteimages/bkgrdprints.gif'; $topperdirectory = 'siteimages'; $video1source = 'randvid.php'; $video2source = 'randvid2.php'; $voiceoversource = 'randvo.php'; $profilepicsdirectory = 'stockimages'; $mainimage = 'banners'; $gallerydirectory = '/images/Wide-Area Persistent Surveillance/'; – teame Sep 24 '15 at 02:11
  • So if a user puts in a link, like your example, does it get saved to a database? – Rasclatt Sep 24 '15 at 03:17
  • Also, if you could provide more of this tightly coupled script, it may be easier to see what you are trying to do. Right now it's somewhat unclear based on your example(s) and explanation(s) – Rasclatt Sep 24 '15 at 03:21

1 Answers1

1

Assuming that randvid.php is already working, you don't need to make it echo or print at all. When you include another php file that you have access to (e.g. a file on the same server), you also get access to all the variables defined in the file.

So in randvid.php, you could define a variable $videourl that contains the url of the video, and then all you have to do is use that variable.

$video1sourcedir = $videourl;

<video src="<?php echo $videourl; ?>" width="400" height="225" controls autoplay loop preload>

Alternatively, put the logic of randvid.php inside a function.

function getRandVid() {
    // Do stuff and return a url for the video.
    return $videourl;
}

Then when you include randvid.php, you will also get access to the function.

$video1sourcedir = getRandVid();

<video src="<?php echo getRandVid(); ?>" width="400" height="225" controls autoplay loop preload>
Zsw
  • 3,920
  • 4
  • 29
  • 43
  • The problem isn't that the function won't work, it's that I am placing it at the very top of the template "code " for volunteers to hand edit. They 'hand-code define' the $variables at the top of the template document to customize where the links point. But sometimes the media is a whole directory of images (and/or videos), so then they have to be able to paste in the snippet that does an include function... I want to gather that snippet as a variable alongside the rest... does that make sense? Otherwise they won't be able to "find where to put it." – teame Sep 24 '15 at 23:17
  • I also have to have the randomvid.php as it's own file, since sometimes it's not needed, (and it is designed that way already & breaks if I try to change it.) – teame Sep 24 '15 at 23:17
  • So "video1sourcedir = '/documents/sword.mov'" goes alongside a bunch of other things they can define in one place, at the top of the document they edit. This allows the document to work as a template to scale up the site to include more pages quickly (without massive re-development of the whole site to be coded "correctly") – teame Sep 24 '15 at 23:20