Persoonlijke afbeelding tonen in PHP

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Wouter smets

wouter smets

20/02/2018 21:57:09
Quote Anchor link
beste,

ik heb een leuk script gevonden voor mijn foto's te bewaren. hierbij kan ik ook mp4 laten afspelen.
echter bij de thumbs zit ik met een vaste afbeelding voor iedere mp4 (foliogallery/images/video.png) ik heb ondertussen al gevonden als ik dit verander naar ($mp4_thumb = $album.'/thumbs/'.$filename.'.jpg';) kan ik een gepersonaliseerde jpg weergeven van de mp4.


maar hoe kan ik dit programmeren indien er geen gepersonaliseerde jpg bestaat toch de vaste afbeelding wordt weergegeven?

waarschijnlijk met de echo functie maar ik heb echter zero kennis van php.

alvast bedankt voor de hulp.

uitgeknipt stukje script
------------------------
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
            foreach($files as $file)
            {
                   
                if(isset($file) && is_file($album .'/'. $file))
                {
                       
                    $file_parts = pathinfo($file);
                    $filename = $file_parts['filename'];
                    $ext = $file_parts['extension'];
                    
                    $full_caption = (itemDescription($album, $file) ? itemDescription($album, $file) : $file); // image captions
                    $caption = encodeto($full_caption);          
                    
                    if (file_exists($album.'/thumbs/'.$file))
                    {

                        $thumb = '<img src="'.$album.'/thumbs/'.$file.'" alt="'.$file.'" />';
                    }

                    else
                    {
                        if($ext=='mp4')
                        {

                            //$mp4_thumb = file_exists($album .'/thumbs/'.$filename.'.jpg') ? $filename.'.jpg' : 'foliogallery/images/mp4.png';
                            //$thumb = '<img src="'.$album.'/thumbs/'.$mp4_thumb.'" alt="" />';

                            $mp4_thumb = 'foliogallery/images/video.png';
                            $thumb = '<img src="'.$mp4_thumb.'" alt="'.$file.'" />';
                        }

?>




Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<!--
    folioGallery v3.1 - 2017-09-18
    (c) 2017 Harry Ghazanian - foliopages.com/php-jquery-ajax-photo-gallery-no-database
    This content is released under the http://www.opensource.org/licenses/mit-license.php MIT License.
-->
<?php
include 'foliogallery/config.php';
$targetid = isset($_POST['targetid']) ? $_POST['targetid'] : ''; // id of gallery or album
?>


<div class="fg">

<?php
if (empty($_REQUEST['album'])) // if no album requested, show all albums
{        
    
    $albums = array();
    $albums = glob($mainFolder.'/*', GLOB_ONLYDIR); // scan only directories
    $numAlbums = count($albums);
    
    // sort the abums array    
    if($sort_albums == 'newest')
    {

        array_multisort(array_map('filemtime', $albums ), SORT_NUMERIC, SORT_DESC, $albums);
    }

    elseif($sort_albums == 'oldest')
    {

        array_multisort(array_map('filemtime', $albums ), SORT_NUMERIC, SORT_ASC, $albums);
    }

    else
    {
        sort($sort_albums);
    }

                
    if($numAlbums == 0)
    {

        echo '<div class="titlebar"><p>No albums posted</p></div>';
    }

    else
    {
                  
        if($show_title)
        {
?>

            <span class="title m5-left">Photo Gallery - <?php echo $numAlbums; ?> albums</span>
                
            <div class="clear"></div>
        <?php
        } ?>

        
        <div class="thumbwrap-outer">
        <?php
        if($show_nav)
        {
?>

            <!--<a href="#" class="toleft"><span class="fgleft"></span></a>
            <a href="#" class="toright"><span class="fgright"></span></a>-->
            <a href="#" class="fgleft"></a>
            <a href="#" class="fgright"></a>
        <?php
        } ?>

        <div class="thumbwrap" title="<?php echo $numAlbums; ?>">
        <div class="thumbwrap-inner">
            <?php         
            foreach($albums as $album)
            {
                                                                                      
                $album = basename($album); // extract folder name from path
                
                $thumb_pool = glob($mainFolder.'/'.$album.'/*.{'.$supported_extensions.'}', GLOB_BRACE);        
                                
                if (count($thumb_pool) == 0)
                {

                    $thumb = $no_thumb;
                }

                else
                {    
                    $rand_thumb = ($random_thumbs ? $thumb_pool[array_rand($thumb_pool)] : $thumb_pool[0]); // display a random thumb or the 1st thumb    
                    $rand_thumb = basename($rand_thumb);
                    
                    if(file_exists($mainFolder.'/'.$album.'/thumbs/'.$rand_thumb))
                    {

                        $thumb = '<img src="'.$mainFolder.'/'.$album.'/thumbs/'.$rand_thumb.'" alt="'.$rand_thumb.'" />';
                    }

                    else
                    {        
                        $file_parts = pathinfo($rand_thumb);
                        $filename = $file_parts['filename'];
                        $ext = $file_parts['extension'];
                                            
                        if($ext=='mp4')
                        {

                            //$mp4_thumb = file_exists($album .'/thumbs/'.$filename.'.jpg') ? $filename.'.jpg' : 'foliogallery/images/mp4.png';
                            //$thumb = '<img src="'.$album.'/thumbs/'.$mp4_thumb.'" alt="" />';

                            $mp4_thumb = 'foliogallery/images/video.png';
                            $thumb = '<img src="'.$mp4_thumb.'" alt="'.$album.'" />';
                        }

                        elseif($ext=='mp3')
                        {

                            //$mp3_thumb = file_exists($album .'/thumbs/'.$filename.'.jpg') ? $filename.'.jpg' : 'foliogallery/images/mp3.png';
                            //$thumb = '<img src="'.$album.'/thumbs/'.$mp3_thumb.'" alt="" />';

                            $mp3_thumb = 'foliogallery/images/note.png';
                            $thumb = '<img src="'.$mp3_thumb.'" alt="'.$album.'" />';
                        }

                        else
                        {
                            $thumb = $no_thumb;
                        }

                    }
                                    
                }
?>

                                
                <div class="thumb">
                    <div class="thumb-itself">
                        <a class="showAlb" rel="<?php echo $album; ?>" href="<?php echo $_SERVER['PHP_SELF']; ?>?album=<?php echo urlencode($album); ?>">
                            <?php echo $thumb; ?>
                        </a>
                    </div>
                    <div class="clear"></div>    
                    <div class="caption"><?php echo $album; ?></div>
                </div>
            <?php    
            } ?>

        
        </div>
        </div>    
        </div>

    <?php
    }

}

else //display photos in album
{

    $requested_album = sanitize($_REQUEST['album']); // xss prevention
    $album = $mainFolder.'/'.$requested_album;
    
    $scan_files = array();
    $scan_files = glob($album.'/*.{'.$supported_extensions.'}', GLOB_BRACE);
    $numFiles = count($scan_files);
        
    // sort the files array    
    if($sort_files == 'newest')
    {

        array_multisort(array_map('filemtime', $scan_files ), SORT_NUMERIC, SORT_DESC, $scan_files);
    }

    elseif($sort_files == 'oldest')
    {

        array_multisort(array_map('filemtime', $scan_files ), SORT_NUMERIC, SORT_ASC, $scan_files);
    }

    else
    {
        sort($scan_files);
    }

    
    $files = array();
    foreach($scan_files as $f) { $files[] = basename($f); }
        
    if($show_title)
    {
    
        if($fullAlbum==1)
        {
?>

            <a class="title refresh m5-left" href="#">Index</a>
            <span class="navigate-next"></span>
            <span class="title"><?php echo $requested_album; ?> - <?php echo $numFiles; ?> images</span>
        <?php
        }
        else
        { ?>

            <span class="title m5-left"><?php echo $requested_album; ?> - <?php echo $numFiles; ?> images</span>
        <?php
        } ?>

      
           <div class="clear"></div>
    <?php
    }
    
    if($numFiles == 0)
    {

        echo '<div class="clear"></div>There are no images in this album.';    
    }

    else    
    {                            
                
        if (!is_dir($album.'/thumbs'))
        {

            mkdir($album.'/thumbs');
            chmod($album.'/thumbs', 0777);
            //chown($album.'/thumbs', 'apache');
        } ?>


        <div class="thumbwrap-outer">
        <?php
        if($show_nav)
        {
?>

            <!--<a href="#" class="toleft"><span class="fgleft"></span></a>
            <a href="#" class="toright"><span class="fgright"></span></a>-->
            <a href="#" class="fgleft"></a>
            <a href="#" class="fgright"></a>
        <?php
        } ?>

        <div class="thumbwrap" title="<?php echo $numFiles; ?>">        
        <div class="thumbwrap-inner">
        
            <?php
            foreach($files as $file)
            {
                   
                if(isset($file) && is_file($album .'/'. $file))
                {
                       
                    $file_parts = pathinfo($file);
                    $filename = $file_parts['filename'];
                    $ext = $file_parts['extension'];
                    
                    $full_caption = (itemDescription($album, $file) ? itemDescription($album, $file) : $file); // image captions
                    $caption = encodeto($full_caption);          
                    
                    if (file_exists($album.'/thumbs/'.$file))
                    {

                        $thumb = '<img src="'.$album.'/thumbs/'.$file.'" alt="'.$file.'" />';
                    }

                    else
                    {
                        if($ext=='mp4')
                        {

                            //$mp4_thumb = file_exists($album .'/thumbs/'.$filename.'.jpg') ? $filename.'.jpg' : 'foliogallery/images/mp4.png';
                            //$thumb = '<img src="'.$album.'/thumbs/'.$mp4_thumb.'" alt="" />';

                            $mp4_thumb = 'foliogallery/images/video.png';
                            $thumb = '<img src="'.$mp4_thumb.'" alt="'.$file.'" />';
                        }

                        elseif($ext=='mp3')
                        {

                            //$mp3_thumb = file_exists($album .'/thumbs/'.$filename.'.jpg') ? $filename.'.jpg' : 'foliogallery/images/mp3.png';
                            //$thumb = '<img src="'.$album.'/thumbs/'.$mp3_thumb.'" alt="" />';

                            $mp3_thumb = 'foliogallery/images/note.png';
                            $thumb = '<img src="'.$mp3_thumb.'" alt="'.$file.'" />';
                        }

                        else
                        {
                            make_thumb($album,$file,$album.'/thumbs/'.$file,$make_thumb_width);
                        }
                    }

                    ?>
      
                  
                    <div class="thumb">
                        
                        <div class="thumb-itself"><?php echo url_start($album,$file).$thumb.$url_end; ?></div>
                        
                        <?php
                        if($show_captions)
                        {
?>

                            <div class="clear"></div>
                            <div class="caption">
                                <a href="#" class="tooltip" rev="<?php echo $caption; ?>"><?php echo $caption; ?></a>
                            </div>
                        <?php
                        } ?>

                        
                    </div>
                        
                <?php                
                }
            
            }
?>

        
        </div>
        </div>
        </div>
        
        <?php
        if($show_descriptions)
        {

            echo (file_exists($album.'/descriptions.txt') ? '<div class="description-wrapper">'.encodeto(itemDescription($album)).'</div>' : ''); //display album description
          }
      
    }
// end if numFiles not 0

} ?>

</div>

<div id="fgOverlay"></div>    

<script>
$(function() {
    
    var targetid = <?php echo $targetid; ?>;
    var pid = $(targetid).attr('id');
    var pid = '#'+pid;
    var captionHeight = $(pid+' .caption').outerHeight(true);
    var thumbHeight = <?php echo $thumb_height; ?> + captionHeight;
    
    $(pid+' .fg').css({'max-width':'<?php echo $canvas_width; ?>px'});
    $(pid+' .thumb').width(<?php echo $thumb_width; ?>);
    $(pid+' .thumb').height(thumbHeight);
    $(pid+' .thumb-itself').height(<?php echo $thumb_height; ?>);    
    var numThumbs = $(pid+' .thumbwrap').attr('title');
    
    // number of thumbs to display per row
    var thumbsPerRow = Math.ceil(numThumbs /  <?php echo $num_rows; ?>);
    
    // get slider width
    var sliderWidth = thumbsPerRow * <?php echo $thumb_width_padded; ?>;    
    
    // must set slider width to enable horizontal scrolling            
    $(pid+' .thumbwrap-inner').css({'width':+sliderWidth+'px', 'height':'<?php echo $canvas_max_height; ?>px'});
    
    // enable disable prev next buttons at startup
    var newScrollLeft = $(pid+' .thumbwrap').scrollLeft();
    if(newScrollLeft == 0) { $(pid+' .fgleft').hide(); }    
    if(sliderWidth - newScrollLeft == <?php echo $canvas_width; ?>) { $(pid+' .fgright').hide(); }
        
});
</script>


Edit:
Titel aangepast van 'probleem' naar 'Persoonlijke afbeelding tonen in PHP'. Gelieve in het vervolg een duidelijkere topictitel aan te geven.
Gewijzigd op 20/02/2018 22:46:44 door - Ariën -
 
PHP hulp

PHP hulp

26/12/2024 12:19:09
 
Thomas van den Heuvel

Thomas van den Heuvel

21/02/2018 16:36:08
Quote Anchor link
Wouter smets op 20/02/2018 21:57:09:
maar hoe kan ik dit programmeren indien er geen gepersonaliseerde jpg bestaat toch de vaste afbeelding wordt weergegeven?

Waarschijnlijk wederom met file_exists() (een controle of een afbeelding bestaat), of liever gezegd, een uitbreiding van dit if-blok met een else-component voor wanneer dit niet het geval is. Maar alles in dat eerste codefragment heet zo'n beetje $thumb, dus ik weet niet precies wat waarvoor dient.
 
Wouter smets

wouter smets

22/02/2018 21:37:53
Quote Anchor link
bedankt voor de reactie,

ondertussen zelf gevonden.

$mp4_thumb = 'foliogallery/images/video.png';

moet worden.

$mp4_thumb = file_exists($album .'/thumbs/'.$filename.'.jpg') ? $album .'/thumbs/'.$filename.'.jpg' : 'foliogallery/images/video.png';
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.