upload and show(select) video in php - php

I make a form through i can upload images and videos, the file's are stor in some folder and the path is stored in mysql table, now when i select the image file then i would show properly, my image selection code is...
$smt=$conn->prepare('SELECT * FROM post');
$smt->execute();
<?php while($gdata=$smt->fetch(PDO::FETCH_OBJ)):?>
<img src="posts/<?php echo $gdata->Post_Path; ?>" alt="image" class="post-image"/>
<div class="media-body col-md-8 post-image-space pull-left">
<div class="post-overview">
<ul>
<li class="post-category"><?php echo $gdata->Category;?></li>
<li class="post-timestemp">Post on <?php echo $gdata->Post_Date;?></li>
</ul>
<h4 class="media-heading h4"><?php echo $gdata->Title;?></h4>
<p class="post-text"><?php echo $gdata->Post;?></p>
</div>
</div>
<?php endwhile;?>
now the problem is that through the above way i can access the video file but it can't be shown? How can i check that the file is image or video?
In my database the path will store like, example.jpg/mypic.png, test.mp4, how can i check the last extension of file?
my updated code is...
<?php
include 'conn.php';
$smt=$conn->prepare('SELECT * FROM post');
$smt->execute();
$row=$smt->fetch(PDO::FETCH_OBJ);
$row->Post_Path;
$ext=pathinfo($row,PATHINFO_EXTENSION);
?>
<?php if($ext=='mp4')
{?>
<?php while($gdata=$smt->fetch(PDO::FETCH_OBJ)):?>
<a href="#" class="media-left col-md-4 clearfix"><video class="post-image" controls>
<source src="posts/<?php echo $gdata->$ext;?>" type="video/mp4">
</video></a>
<div class="media-body col-md-8 post-image-space pull-left">
<div class="post-overview">
<ul>
<li class="post-category"><?php echo $gdata->Category;?></li>
<li class="post-timestemp">Post on <?php echo $gdata->Post_Date;?></li>
</ul>
<h4 class="media-heading h4"><?php echo $gdata->Title;?></h4>
<p class="post-text"><?php echo $gdata->Post;?></p>
</div>
</div>
<?php endwhile;
}
elseif($ext=='jpg||jpeg||png')
{
?>
<?php while ($gdata = $smt->fetch(PDO::FETCH_OBJ)): ?>
<a href="#" class="media-left col-md-4 clearfix"><img src="posts/<?php echo $gdata->Post_Path; ?>" alt="image"
class="post-image"/></a>
<div class="media-body col-md-8 post-image-space pull-left">
<div class="post-overview">
<ul>
<li class="post-category"><?php echo $gdata->Category; ?></li>
<li class="post-timestemp">Post on <?php echo $gdata->Post_Date; ?></li>
</ul>
<a href="post-description.php?id=<?php echo $gdata->Id ?>"><h4
class="media-heading h4"><?php echo $gdata->Title; ?></h4></a>
<p class="post-text"><?php echo $gdata->Post; ?></p>
</div>
</div>
<?php endwhile;
}?>
I am not able to show video in my index page, how to show it, however i am able to show the image..
Any help would be appreciated.

$info = new SplFileInfo('testing.jpg');
var_dump($info->getExtension());
Reference
Before someone comes in and says this requires extra installations
This extension is available and compiled by default in PHP 5.0.0.
Reference

Check this one. which may helps you..
For PHP < 5.3 use mime_content_type()
For PHP >= 5.3 use finfo_fopen()
$smt=$conn->prepare('SELECT * FROM post');
$smt->execute();
<?php while($gdata=$smt->fetch(PDO::FETCH_OBJ)):
$mime = mime_content_type($gdata->Post_Path);
if(strstr($mime, "video/")){
// this code for video
$file='';
}else if(strstr($mime, "image/")){
// this code for image
$file='<img src="posts/'.$gdata->Post_Path.'" alt="image" class="post-image"/>';
}
?>
<?php echo $file?>
<div class="media-body col-md-8 post-image-space pull-left">
<div class="post-overview">
<ul>
<li class="post-category"><?php echo $gdata->Category;?></li>
<li class="post-timestemp">Post on <?php echo $gdata->Post_Date;?></li>
</ul>
<h4 class="media-heading h4"><?php echo $gdata->Title;?></h4>
<p class="post-text"><?php echo $gdata->Post;?></p>
</div>
</div>
<?php endwhile;?>
mime_content_type Should work for most file extentions.

Try this:
$fileInfo = pathinfo($gdata->Post_Path);
if($fileInfo['extension'] == 'png')
{
echo "It's an PNG";
}
elseif($fileInfo['extension'] == 'mp4')
{
echo "It's an MP4";
}

$file_parts = pathinfo($filename);
switch($file_parts['extension'])
{
case "jpg":
break;
case "exe":
break;
case "": // Handle file extension for files ending in '.'
case NULL: // Handle no file extension
break;
}
may be it's help you.try it

Related

Adding Image to Carousel Slider

enter image description here
<div id="demo" class="carousel slide" data-ride="carousel">
<?php $count = count($veriler);?>
<ul class="carousel-indicators">
<?PHP
$i=0;
for ($i=0;$i<$count;$i++) { ?>
<li data-target="#demo" data-slide-to="<?php echo $i; ?>"></li>
<?php } ?>
</ul>
<div class="carousel-inner">
<?php
$j=0;
foreach ($veriler as $row) { ?>
<div class="item <?php if($j==0) { echo "active"; } ?>">
<div style="max-width:1100px; max-height:500px;">
<img src=" <?php echo $row["haberekle_konu"]; ?>" alt="Los Angeles">
</div>
<div class="carousel-caption">
<h3> <?php echo $row["haberekle_baslik"]; ?> </h3>
</div>
</div>
<?php $j++; } ?>
</div>
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
i want to add in Carousel Slider a few images.
i posted image and caption from admin panel and i saved to database. when i extracted data from the database, result that: See i added the image. No picture display.
enter image description here
<?php
$veriler = $db->query("SELECT * FROM haberlerekle",PDO::FETCH_ASSOC)->fetchAll();
?>
i think, that codes need.
The symbol the top left cornor(https://i.stack.imgur.com/7UgIN.jpg) indicates a "broken link".
This means, the path does not point on a File.
Or u maybe need a absolute/relativ path(HTML showing broken image)
Make sure the path of the image u try to paste in the src-attribute is realy there.
U can try it by pasting the content of
$row["haberekle_konu"]
behind the URL.
If the image not appear, the path ist not correct.
Eventually i found the codes i was looking for. i found youtube. The codes and youtube link below.
Youtube Link
slider.php
<?php
$veriler = $db->query("SELECT * FROM haberlerekle ORDER BY haberekle_id DESC LIMIT 12",PDO::FETCH_ASSOC)->fetchAll();
/* $veriler = $db->query("SELECT * FROM haberlerekle ORDER BY haberekle_id DESC LIMIT 7"PDO::FETCH_ASSOC)->fetchAll(); */
?>
<div id="demo" class="carousel slide" data-ride="carousel">
<ul class="carousel-indicators">
<?php
$i = 0;
foreach ($veriler as $row) {
$actives = '';
if($i == 0) {
$actives = 'active';
}
?>
<li data-target="#demo" data-slide-to="<?php echo $i; ?>" class="<?php echo $actives; ?>"></li>
<?php $i++; } ?>
</ul>
<div class="carousel-inner">
<?php
$i = 0;
foreach ($veriler as $row) {
$actives = '';
if($i == 0) {
$actives = 'active';
}
?>
<div class="carousel-item <?php echo $actives; ?>">
<img src="upload/images/<?php echo $row['haberekle_konu']; ?>" width="832" height="502">
<div class="carousel-caption">
<p><?php echo $row["haberekle_baslik"]; ?></p>
</div>
</div>
<?php $i++; } ?>
</div>
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
admin.php
<?php
if(isset($_POST['resimyukle'])) {
$yazi = $_POST['haberekle_baslik'];
$yukleklasor = "../../../upload/images";
$tmp_name = $_FILES['yukle_resim']['tmp_name'];
$name = $_FILES['yukle_resim']['name'];
$boyut = $_FILES['yukle_resim']['size'];
$tip = $_FILES['yukle_resim']['type'];
$uzanti = substr($name,-4,4);
$rasgelesayi1 = rand(10000,50000);
$rasgelesayi2 = rand(10000,50000);
$resimad = $rasgelesayi1.$rasgelesayi2.$uzanti;
//dosya var mı kontrol
if(strlen($name) == 0) {
echo "Bir Dosya Seçiniz";
exit();
}
//boyut kontrol
if($boyut > (1024*1024*3)) {
echo "Dosya Boyutu Çok Fazla";
exit();
}
//tip kontrol
if($tip != 'image/jpeg' && $tip != 'image/png' && $uzanti != '.jpg') {
echo "Yalnızca jpeg veya png formatında olabilir";
}
move_uploaded_file($tmp_name, "$yukleklasor/$resimad");
$resimsor = $db->prepare("INSERT INTO haberlerekle set haberekle_konu=:ad, haberekle_baslik=:baslik");
$resimyukle = $resimsor->execute(array('ad'=> $resimad, 'baslik'=> $yazi));
}
?>
<form action="" method="post" enctype="multipart/form-data">
<input type="text" name="haberekle_baslik" size="100"></input><br><br>
<input type="file" name="yukle_resim" /><br>
<input type="submit" value="Yükle" name="resimyukle" />
</form>
Thank you for your help.

PHP: link a Block

quick question, i want to link the BLOCK1 to another page. Is it possible? do anyone got a solution? i have tried abit and my brain is going mad T_T. there are 5 other blocks that i which to link to other pages aswell.
this is the code below:
<div class="midrow_block axn_block1">
<div class="mid_block_content">
<!--BLOCK1 IMAGE-->
<?php if(!empty($optimizer['block1_image']['url']) && empty($optimizer['block1_img_bg'])){ ?>
<div class="block_img"><img src="<?php echo $optimizer['block1_image']['url']; ?>" width="<?php echo $optimizer['block1_image']['width']; ?>" height="<?php echo $optimizer['block1_image']['height']; ?>" /></div>
<?php } ?>
<div class="block_content">
<h3>
<?php echo do_shortcode( $optimizer['block1_text_id']); ?>
</h3>
<?php echo do_shortcode($optimizer['block1_textarea_id']); ?>
</div>
</div>
</div>
</div>
<?php } ?>
<!--BLOCK1 END-->
Just put a <a>-Tag arount the block you want to link:
<a href="'your link here'"> <!-- start link here -->
<div class="midrow_block axn_block1">
<div class="mid_block_content">
<!--BLOCK1 IMAGE-->
<?php if(!empty($optimizer['block1_image']['url']) && empty($optimizer['block1_img_bg'])){ ?>
<div class="block_img"><img src="<?php echo $optimizer['block1_image']['url']; ?>" width="<?php echo $optimizer['block1_image']['width']; ?>" height="<?php echo $optimizer['block1_image']['height']; ?>" /></div>
<?php } ?>
<div class="block_content">
<h3>
<?php echo do_shortcode( $optimizer['block1_text_id']); ?>
</h3>
<?php echo do_shortcode($optimizer['block1_textarea_id']); ?>
</div>
</div>
</div>
</a> <!-- end link here -->
Or put it around any other part you want to have the link on. It's just basic HTML and has nothing to do with PHP.
here is the fullcode of the block. i missed to copy the top of it:
<?php if ((!empty ($optimizer['block1_text_id'])) || (!empty ($optimizer['block1_textarea_id'])) ) { ?>
<div class="midrow_block axn_block1">
<div class="mid_block_content">
<!--BLOCK1 IMAGE-->
<?php if(!empty($optimizer['block1_image']['url']) && empty($optimizer['block1_img_bg'])){ ?>
<div class="block_img"><img src="<?php echo $optimizer['block1_image']['url']; ?>" width="<?php echo $optimizer['block1_image']['width']; ?>" height="<?php echo $optimizer['block1_image']['height']; ?>" /></div>
<?php } ?>
<div class="block_content">
<h3>
<?php echo do_shortcode( $optimizer['block1_text_id']); ?>
</h3>
<?php echo do_shortcode($optimizer['block1_textarea_id']); ?>
</div>
</div>
</div>
You can use with this JS
<div class="midrow_block axn_block1" onclick="location.href='url'">content</div>
jQuery:
$("div").click(function(){
window.location=$(this).find("a").attr("href"); return false;
});

Arrange divs on new row every third time

I have this most annoying problem; I'm trying to arrange three divs on a row, and then new row, and another three divs and so on, like this:
<div class="container">
<div class="row">
<div class="col-sm-1">1</div>
<div class="col-sm-1">2</div>
<div class="col-sm-1">3</div>
</div>
<div class="row">
<div class="col-sm-1">4</div>
<div class="col-sm-1">5</div>
<div class="col-sm-1">6</div>
</div>
</div>
As for this accepted answer,
There is one catch: 0 % 3 is equal to 0. This could result in
unexpected results if your counter starts at 0.
So how would i implement this into this code:
<div class="col-md-8">
<?php
foreach($this->movies->movie_data as $key => $movie){
$string = file_get_contents("http://example.com/?t=" . urlencode($movie->movie_titel). "&y=&plot=short&r=json");
$result = json_decode($string);
if($result->Response == 'True'){
?>
<div class="col-sm-4">
<?php if($result->Poster == 'N/A') : ?>
<a href="<?php echo Config::get('URL')?>ladybug/day/<?php echo $this->city ?>/<?php echo $movie->movie_id ?>">
<img src="<?php echo Config::get('URL')?>/images/na.png" class="img-responsive img-thumbnail"></a>
<?php else: ?>
<a href="<?php echo Config::get('URL')?>ladybug/day/<?php echo $this->city ?>/<?php echo $movie->movie_id ?>">
<img src="<?php echo $result->Poster; ?>" class="img-responsive img-thumbnail"></a>
<?php endif; ?>
<div><b><?php echo $result->Title; ?></b></div>
<div><i><?php // echo $result->Plot; ?></i></div>
</div>
<?php }else{ ?>
<div class="col-sm-4">
<a href="<?php echo Config::get('URL')?>ladybug/day/<?php echo $this->city ?>/<?php echo $movie->movie_id ?>">
<img src="<?php echo Config::get('URL')?>/images/na.png" class="img-responsive img-thumbnail"></a>
<div><b><?php echo $movie->movie_titel ?></b></div>
<div class="plot"><i><?php //echo 'N/A' ?></i></div>
</div>
<?php }}} ?
</div>
For some reason, divs is arranged like this:
My question: How do I arrange thumbnails on a new row, every third time?
Found the answer in the other Q... Didn't read, sorry about that.
<?php }
if (($key + 1) % 3 == 0) { ?>
</div>
<?php }
}} ?>

Display nav list of content is available with php

I've got this PHP code:
<div class="connect_wrap <?php echo $this->class; ?> block" <?php echo $this->cssID; ?>>
<?php if(!$this->empty): ?>
<?php foreach($this->entries as $entry): ?>
<div class="entry block <?php echo $entry->class; ?>">
<div class="tab">
<ul class="tabs">
<li class="tab-link current" data-tab="Kunden">Kunden</li>
<li class="tab-link" data-tab="Loesungen">Lösungen</li>
</ul>
<?php
$this->import('Database');
$pName = $entry->field('name')->value();
$result = \Database::getInstance()->prepare("SELECT * FROM kunden WHERE partner=?")->execute($pName);
?>
<?php if($result->numRows):?>
<div id="Kunden" class="tab-content current">
<?php while($result->next()) { ?>
<div class="items">
<a href="{{env::url}}/kunden-detail/<?php echo $result->alias; ?>">
<div class="logo">
<img src="<?php $objFile = \FilesModel::findByUuid($result->logo); echo $objFile->path;?>"width="180" height="135">
</div>
</a>
</div>
<?php } ?>
</div>
<?php endif;?>
<?php
$this->import('Database');
$pName = $entry->field('name')->value();
$result = \Database::getInstance()->prepare("SELECT * FROM solutions WHERE solution_provider=?")->execute($pName);
?>
<?php if($result->numRows):?>
<div id="Loesungen" class="tab-content">
<?php while($result->next()) { ?>
<div class="items">
<a href="{{env::url}}/synaptic-commerce-solution/<?php echo $result->alias; ?>">
<div class="logo">
<img src="<?php $objFile = \FilesModel::findByUuid($result->logo); echo $objFile->path;?>"width="180" height="135">
</div>
</a>
</div>
<?php } ?>
</div>
<?php endif;?>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<?php endif;?>
In that code, I've got two DB queries. My problem is, if there is no data for both queries, the div with the class "connect_wrap" should not be displayed.
How can I do that?
Thanks in advance.
do you want to check if the query has data in it and its not empty ? if so try num_rows it will return the number of rows that the query found/affected for example to check if th query returned one or more rows
if($result->num_rows >= 1) {
//do stuf
} else {
// no result found
}
Move the query execution up or preferably: not within the html but in a different file/class. Then add a check before the content_wrap div: if($kundenResult->num_rows >= 1 || $solutionsResult->num_rows >= 1). If you just keep the individual checks like you already have, it will only show the content_wrap div if either or both of the queries return rows of data.

Multilingual slideshow

I have this code for a slideshow in my Drupal 7, Nexus 7.x-1.3 theme.
My website is multilingual and I need to use a different image for every language, eg. I would like to change slide-image-1.jpg (en language) with other image-name for (gr language).
My code:
<?php if ($is_front): ?>
<?php if (theme_get_setting('slideshow_display','nexus')): ?>
<?php
$slide1_head = check_plain(theme_get_setting('slide1_head','nexus')); $slide1_desc = check_markup(theme_get_setting('slide1_desc','nexus'), 'full_html'); $slide1_url = check_plain(theme_get_setting('slide1_url','nexus'));
$slide2_head = check_plain(theme_get_setting('slide2_head','nexus')); $slide2_desc = check_markup(theme_get_setting('slide2_desc','nexus'), 'full_html'); $slide2_url = check_plain(theme_get_setting('slide2_url','nexus'));
$slide3_head = check_plain(theme_get_setting('slide3_head','nexus')); $slide3_desc = check_markup(theme_get_setting('slide3_desc','nexus'), 'full_html'); $slide3_url = check_plain(theme_get_setting('slide3_url','nexus'));
?>
<div id="slidebox" class="flexslider">
<ul class="slides">
<li>
<img src="<?php print base_path() . drupal_get_path('theme', 'nexus') . '/images/slide-image-1.jpg'; ?>"/>
<?php if($slide1_head || $slide1_desc) : ?>
<div class="flex-caption">
<h2><?php print $slide1_head; ?></h2><?php print $slide1_desc; ?>
<a class="frmore" href="<?php print url($slide1_url); ?>"> <?php print t('CONTACT US'); ?> </a>
</div>
<?php endif; ?>
</li>
<li>
<img src="<?php print base_path() . drupal_get_path('theme', 'nexus') . '/images/slide-image-2.jpg'; ?>"/>
<?php if($slide2_head || $slide2_desc) : ?>
<div class="flex-caption">
<h2><?php print $slide2_head; ?></h2><?php print $slide2_desc; ?>
<a class="frmore" href="<?php print url($slide2_url); ?>"> <?php print t('CONTACT US'); ?> </a>
</div>
<?php endif; ?>
</li>
<li>
<img src="<?php print base_path() . drupal_get_path('theme', 'nexus') . '/images/slide-image-3.jpg'; ?>"/>
<?php if($slide3_head || $slide3_desc) : ?>
<div class="flex-caption">
<h2><?php print $slide3_head; ?></h2><?php print $slide3_desc; ?>
<a class="frmore" href="<?php print url($slide3_url); ?>"> <?php print t('CONTACT US'); ?> </a>
</div>
<?php endif; ?>
</li>
</ul><!-- /slides -->
<div class="doverlay"></div>
</div>
<?php endif; ?>
<?php endif; ?>
Is there any solution for that? Thank you.
There is a Drupal connector from Smartling that may be of help. Here is a video showing how the connector works.
Many sites running on Smartling do language/country-specific image replacement, which is explained here.
Hope this helps,
Nataly
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<SCRIPT>
function english(){
$(#image).attr('src','http://link.to.your/english/image.png')
}
function greek(){
$(#image).attr('src','http://link.to.your/greek/image.png')
}
</SCRIPT>
<IMG id="image" src="http://link.to.your/greek/image.png">
Change to English<BR>
Change to Greek
Finally I fixed it in page.tpl with php code. One if/else on your page language to set you picture path.
Regards, HashKey

Categories