Passing the correct upload identifier to a video player viewer from a multi-image upload field

15 posts by 2 authors in: Forums > CMS Builder
Last Post: January 8, 2013   (RSS)

By gkornbluth - December 27, 2012 - edited: December 30, 2012

Hi All,

I’m using a multi-image upload field and trying to differentiate between still jpg images which show the full sized upload when clicked on and .mp4 videos that link to a video player page which plays the video file.

In the test code below, I can do it successfully with a single video file, but once I upload multiple video files to my multi-image upload field, the video viewer tries to access all of the video files simultaneously and the process falls apart.

I have a feeling that I’m missing something really basic, but I’m not sure how to pass the correct video path to the video viewer and haven’t been able to find the key.

Thanks for any insights.

Jerry Kornbluth

The List page code is:

<?php foreach ($photo_sharingRecords as $record): ?>
<?php echo $record['title']?><br />
<?php foreach ($record['images'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<a href="<?php echo $upload['urlPath'] ?>"> <img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /></a><br/>
<?php elseif($upload['extension'] == 'mp4'): ?>
<a href="photosharingdetailv3.php?<?php echo $record['num']?>">
<?php foreach ($record['video_placeholder_image'] as $upload): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
<?php endforeach ?>
</a><br/>
<?php endif ?>
<?php endforeach ?>
<hr/>
<?php endforeach ?>
___________________________

And the video display detail page code is::

<table width="70%"  align="center" cellpadding="5">
<tr>
 <td><h2 align="center"><?php echo strtoupper($photo_sharingRecord['title']); ?></h2></td>
</tr>
 <tr >
    <?php foreach ($photo_sharingRecord['images'] as $upload): ?>
    <?php if ($upload['extension'] == 'mp4' ):?>
    <td align="center" valign="top" ><div align="center"><span class=" Large-Text"> <b><?php echo $upload['info1']; ?></b></span><br />
<span class=" Image-Labels"><?php echo $upload['info2']; ?><br />
<br />
 </span>
<div id="container">&nbsp;</div>
<script type="text/javascript">
    jwplayer("container").setup({
        
        file: "http://www.elleschorrphotography.com<?php echo $upload['urlPath'] ?>",
        height: 420,
        width: 510,
        image: "http://www.elleschorrphotography.com<?php foreach ($photo_sharingRecord['video_placeholder_image'] as $upload): ?><?php echo $upload['thumbUrlPath2'] ?><?php endforeach ?>",
        autostart: false,
        modes: [
            { type: "html5" },
            { type: "flash", src: "player.swf" }
        ]

    });
</script>
</div></td>
<?php endif ?>
<?php endforeach ?>
 </tr>
</table>

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Hi Jerry,

I'm assuming you only want to display whatever video has been selected on your video detail page, I think you need to modify your code like this:

List page:

<?php foreach ($photo_sharingRecords as $record): ?>
<?php echo $record['title']?><br />
<?php foreach ($record['images'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<a href="<?php echo $upload['urlPath'] ?>"> <img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /></a><br/>
<?php elseif($upload['extension'] == 'mp4'): ?>

<!-- send the num value for the upload section, not the photoSharing sectoin. -->
<a href="photosharingdetailv3.php?<?php echo $upload['num']?>">
<?php foreach ($record['video_placeholder_image'] as $upload): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
<?php endforeach ?>
</a><br/>
<?php endif ?>
<?php endforeach ?>
<hr/>
<?php endforeach ?>

So if we send over the record num for the image it's self as opposed to the photo_sharing section, we can display the specific video file the user is after. Then you need to modify your detail page like this:

<!-- Replace your getRecords function with this mysql_select function. It will search the uploads section for the record the user has selected: -->

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('C:/wamp/www/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

//search the uploads section for the record that has been passed to the page.

$upload = mysql_select('uploads',"num = '".getNumberFromEndOfUrl()."'");
if(!$upload){die("I'm sorry, there isn't a record matching your search terms."); }

?>

<!-- I've removed the foreach loop, as mysql_select will return an array that contains the details of one record. -->

 <?php if ($upload['extension'] == 'mp4' ):?>
    <td align="center" valign="top" ><div align="center"><span class=" Large-Text"> <b><?php echo $upload['info1']; ?></b></span><br />
<span class=" Image-Labels"><?php echo $upload['info2']; ?><br />
<br />
 </span>
<div id="container">&nbsp;</div>
<script type="text/javascript">
    jwplayer("container").setup({
        file: "http://www.elleschorrphotography.com<?php echo $upload['urlPath'] ?>",
        height: 420,
        width: 510,
        image: "http://www.elleschorrphotography.com<?php foreach ($photo_sharingRecord['video_placeholder_image'] as $upload): ?><?php echo $upload['thumbUrlPath2'] ?><?php endforeach ?>",
        autostart: false,
        modes: [
            { type: "html5" },
            { type: "flash", src: "player.swf" }
        ]
    });
</script> 
</div></td>
<?php endif ?>

Let me know if you have any problems with this code.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gkornbluth - January 2, 2013 - edited: January 2, 2013

Hi Greg,

Thanks for looking at this.

It seems that unless I pass the record number in the URL I don’t get the correct record title etc displayed on the detail page.

So here's what I did:

<?php foreach ($photo_sharingRecords as $record): ?>
<?php echo $record['title']?><br />
  <?php // Define the record number as $recnum
$recnum = $record['num'] ?>
<?php foreach ($record['images'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<a href="<?php echo $upload['urlPath'] ?>"> <img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /></a><br/>
<?php elseif($upload['extension'] == 'mp4'): ?>
<a href="photosharingdetailv4.php?<?php echo $upload['num']?>&num=<?php // Add $record number to URL
echo $recnum ?>">
<?php foreach ($record['video_placeholder_image'] as $upload): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
<?php endforeach ?>
</a><br/>
<?php endif ?>
<?php endforeach ?>
<hr/>
<?php endforeach ?>

I think the problem is that I’m accessing the value of  $upload  from the passed record number and not from the upload number because of the combination of the load records code necessary to display the record title and other record based fields:

// load records
list($photo_sharingRecords, $photo_sharingMetaData) = getRecords(array(
'tableName' => 'photo_sharing',
'where'       => whereRecordNumberInUrl(1),
'limit' => '1',
'allowSearch'=> true,
));
$photo_sharingRecord = @$photo_sharingRecords[0]; // get first record

And with the $upload variable defined as:

$upload = mysql_select('uploads',"num = '".getNumberFromEndOfUrl()."'");

So, in effect the value of $upload and the Record Number are the same.

Hope that makes sense...

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Hi Jerry,

If you pass the upload num variable name across in your list page as well:

<?php foreach ($photo_sharingRecords as $record): ?>
<?php echo $record['title']?><br />
  <?php // Define the record number as $recnum
$recnum = $record['num'] ?>
<?php foreach ($record['images'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<a href="<?php echo $upload['urlPath'] ?>"> <img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /></a><br/>
<?php elseif($upload['extension'] == 'mp4'): ?>
<a href="photosharingdetailv4.php?uploadNum=<?php echo $upload['num']?>&num=<?php // Add $record number to URL
echo $recnum ?>">
<?php foreach ($record['video_placeholder_image'] as $upload): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
<?php endforeach ?>
</a><br/>
<?php endif ?>
<?php endforeach ?>
<hr/>
<?php endforeach ?>

then you can get the upoadNum from the request array more easily and grab the data from the uploads section:

// load records
list($photo_sharingRecords, $photo_sharingMetaData) = getRecords(array(
  'tableName' => 'photo_sharing',
  'where'       => whereRecordNumberInUrl(1),
  'limit' => '1',
  'allowSearch'=> true,
));

$photo_sharingRecord = @$photo_sharingRecords[0]; // get first record

//Grab the upload num from the URL

$uploadVar = intval($_REQUEST['uploadNum']);

//set the data from the upoad record to the upload variable. 

$upload = mysql_get('uploads',$uploadVar);

This way you should be able to get both the records from each section. 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Hi Jerry, 

I think the problem might be that your using the $upload variable in your foreach loop on line 93, which is probably overwriting the contents of the $upload variable at the top of the page. I've reattached the file with renamed variables on line 93 to 98.

Thanks

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gkornbluth - January 3, 2013 - edited: January 4, 2013

Hi Greg,

Pretty unobservant of me...

The basic implementation now working after adding the full path:
http://www.elleschorrphotography.com/cmsAdmin/uploads/ to the video file path on line 130 of photosharingdetailv5.php.

One last step to go. Probably another simple missed detail...

When I try to implement this on the real “list”page (photosharingdetailc.php) which uses previous and next paging to display a limited number of thumbnails per page, the same value for uploadNum is passed in the URL no matter which video clip I choose. The page is called by adding the Photosharing record number to the URL. IE: http://www.elleschorrphotography.com/photosharingdetailc.php?17

I think the issue may be causedby the following code around line 205 but I'm not sure.

@$upload = $photo_sharingRecord['images'][$photoIndex]

I’ve attached photosharingdetailc.php

Thanks again for all your help.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Hi Jerry,

I think the problem might be that your using the $upload variable three times to store different data, you could try using three different variable names and see if that helps.

I also noticed that the link that contains the uploadNum on line 218 isn't inside a foreach loop, which I think it should be if it's for each image record.

Thanks

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Hi Greg,

I actually had changed all the instances of upload to unique variables. I then deleted and re-uploaded the revised file (the first one didn't have those changes) and for some reason, the new file did not overwrite the old one.

Anyway, the new one is attached as photosharingdetaild.php

I’m not sure what you mean by “I  also noticed that the link that contains the uploadNum on line 218 isn't inside a foreach loop, which I think it should be if it's for each image record.”

I tried code like:

<?php foreach ($record['image'] as $upload4): ?><?php echo $upload4['num']?><?php endforeach ?>,

but that’s obviously not what you had in mind because that approach just lists all the upload numbers in the upload field.

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

photosharingdetaild.php 13K

Hi Jerry,

i just had a look at:

http://www.elleschorrphotography.com/photosharingdetailv5.php?uploadNum=1466&num=17

This appears to be loading the correctly. I'm beginning to think the issue is to do with the listings page. I've looked at the layout of this page:

http://www.elleschorrphotography.com/photosharingdetailc.php?17

I noticed that the two media player links had the same uploadNum value in the rel tag. It looks as if they're passing over the num value for the medai player image as opposed to the num value for the video, I think this might be what is causing the issue. 

Thanks

Greg

Greg Thomas







PHP Programmer - interactivetools.com