Технологии
Есть $ifile[$i] название файла . расширение. Как убрать . расширение. - вопрос №1578425
Полный ко
<?php
$mainFolder = 'albums'; // folder where your albums are located — relative to root
$albumsPerPage = '6'; // number of albums per page
$itemsPerPage = '6'; // number of images per page
$thumb_width = '150'; // width of thumbnails
//$thumb_height = '85'; // height of thumbnails
$extensions = array(".jpg",".png",".gif",".JPG",".PNG",".GIF"); // allowed extensions in photo gallery
function make_thumb($folder,$src,$dest,$thumb_width) {
$source_image = imagecreatefromjpeg($folder.'/'.$src);
$width = imagesx($source_image);
$height = imagesy($source_image);
$thumb_height = floor($height*($thumb_width/$width));
$virtual_image = imagecreatetruecolor($thumb_width,$thumb_height);
imagecopyresampled($virtual_image,$source_image,0,0,0,0,$thumb_width,$thumb_height,$width,$height);
imagejpeg($virtual_image,$dest,100);
}
function print_pagination($numPages,$urlVars,$currentPage) {
if ($numPages > 1) {
echo 'Странца '. $currentPage .' из '. $numPages;
echo ' ';
if ($currentPage > 1) {
$prevPage = $currentPage — 1;
echo '<a href="?'. $urlVars .'p='. $prevPage.'">««</a> ';
}
for( $e=0; $e < $numPages; $e++ ) {
$p = $e + 1;
if ($p == $currentPage) {
$class = 'current-paginate';
} else {
$class = 'paginate';
}
echo '<a class="'. $class .'" href="?'. $urlVars .'p='. $p .'">'. $p .'</a>';
}
if ($currentPage != $numPages) {
$nextPage = $currentPage + 1;
echo ' <a href="?'. $urlVars .'p='. $nextPage.'">»»</a>';
}
}
}
if (!isset($_GET['album'])) {
// display photos in album
$src_folder = $mainFolder.'/'.$_GET['album'];
$src_files = scandir($src_folder);
$files = array();
foreach($src_files as $file) {
$ext = strrchr($file, '.');
if(in_array($ext, $extensions)) {
array_push( $files, $file );
}
}
if ( count($files) == 0 ) {
echo 'Пусто :(';
} else {
$numPages = ceil( count($files) / $itemsPerPage );
if(isset($_GET['p'])) {
$currentPage = $_GET['p'];
if($currentPage > $numPages) {
$currentPage = $numPages;
}
} else {
$currentPage=1;
}
$start = ( $currentPage * $itemsPerPage ) — $itemsPerPage;
echo '<div class=«titlebar»>
<div class=«float-left»><span class=«title»>'. $_GET['album'] .'</span></div>
<div class=«float-right»>Видео: '.count($files).'</div>
</div>';
echo '<div class=«clear»></div>';
for( $i=$start; $i<$start + $itemsPerPage; $i++) {
if( isset($files[$i]) && is_file( $src_folder .'/'. $files[$i] ) ) {
echo '<div class=«thumb shadow»>
<div class=«thumb-wrapper»>
<a href=«www.youtube.com/embed/'. $Как сюда вставить только название файла??? .'?rel=0&wmode=transparent» class=«youtube cboxElement» rel=«video»>
<img src="'. $src_folder. $files[$i] .'" width="'.$thumb_width.'" alt="" />
</a>
</div>
</div>';
} else {
if( isset($files[$i]) ) {
echo $files[$i];
}
}
}
echo '<div class=«clear»></div>';
;
} // end else
}
?>
Дмитрий август 4, 2015 г.
-
Всего ответов: 1
-
Здравствуйте.
Можно как-то так, например (от последней точки все отбросить)
function extractFName($filename) {
$p = strrpos($filename, '.');
if ($p > 0) return substr($filename, 0, $p);
else return $filename;
}
и вставлять extractFName($ifile[$i]) -
Спасибо за помощь, вроде разобрался сделал так где вывод ссылки:
if( isset($files[$i]) && is_file( $src_folder .'/'. $files[$i] ) )
{
$el = explode('.', $files[$i]);
$id[$i] = $el[0];
echo '<div class=«thumb shadow»>
<div class=«thumb-wrapper»>
<a href=«www.youtube.com/embed/'. $id[$i] .'?rel=0&wmode=transparent» class=«youtube cboxElement» rel=«video»>
<img src="'. $src_folder. $files[$i] .'" width="'.$thumb_width.'" alt="" />
</a>
</div>
</div>';
}