我使用简单的脚本来保存和重新提供照片和描述,它工作正常,但我需要将脚本“jquery.magnific-popup.js”应用于照片,我添加了该功能,我将类添加到了回声中声明,但我不确定是否是真的,这是php文件:
<?php
ini_set('mysql.connect_timeout',300);
ini_set('default_socket_timeout',300);
?>
<html>
<header>
<link rel="stylesheet" href="magnific-popup.css">
</header>
<body>
<form method="post" enctype="multipart/form-data">
<br/>
<input type="file" name="image" />
<br/><br/>
<input type="submit" name="sumit" value="Upload" />
</form>
<?php
if(isset($_POST['sumit']))
{
if(getimagesize($_FILES['image']['tmp_name']) == FALSE)
{
echo "Please select an image.";
}
else
{
$image= addslashes($_FILES['image']['tmp_name']);
$name= addslashes($_FILES['image']['name']);
$image= file_get_contents($image);
$image= base64_encode($image);
saveimage($name,$image);
}
}
displayimage();
function saveimage($name,$image)
{
$con=mysql_connect("localhost","root","");
mysql_select_db("kstark",$con);
$qry="insert into images (name,image) values ('$name','$image')";
$result=mysql_query($qry,$con);
if($result)
{
//echo "<br/>Image uploaded.";
}
else
{
//echo "<br/>Image not uploaded.";
}
}
function displayimage()
{
$con=mysql_connect("localhost","root","");
mysql_select_db("kstark",$con);
$qry="select * from images";
$result=mysql_query($qry,$con);
while($row = mysql_fetch_array($result))
{
echo '<img class="image-link" height="300" width="300" src="data:image;base64,'.$row[2].' "> ';
}
mysql_close($con);
}
?>
<script src="jquery.magnific-popup.js"></script>
<script type="text/javascript">
$('.image-link').magnificPopup({
type: 'image',
mainClass: 'mfp-with-zoom', // this class is for CSS animation below
zoom: {
enabled: true, // By default it's false, so don't forget to enable it
duration: 300, // duration of the effect, in milliseconds
easing: 'ease-in-out', // CSS transition easing function
// The "opener" function should return the element from which popup will be zoomed in
// and to which popup will be scaled down
// By defailt it looks for an image tag:
opener: function(openerElement) {
// openerElement is the element on which popup was initialized, in this case its <a> tag
// you don't need to add "opener" option if this code matches your needs, it's defailt one.
return openerElement.is('img') ? openerElement : openerElement.find('img');
}
}
}); </script>
</body>
</html>
我想知道如何在正确的位置添加类或者是否应该添加任何修改以使脚本有效?
答案 0 :(得分:-1)
已编辑: 请参阅下面的修订版......这仍然是问题吗?
California (3)