【发布时间】:2015-10-06 14:40:50
【问题描述】:
我正在使用简单的脚本来保存和检索照片和描述,它工作正常,但我需要将脚本“jquery.magnific-popup.js”应用于照片,我添加了函数并将类添加到echo 声明,但不确定是否正确。
这是 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>
我想知道如何在正确的位置添加类,或者是否应该添加任何修改以使脚本正常工作?
【问题讨论】:
-
与问题无关,但不要在 PHP 中使用 mysql 扩展。它已被弃用一段时间,并在 PHP 7 中正式删除。改用 mysqli 或 PDO。
-
在您的 Firefox 中安装 Firebug 并检查是否有错误。
-
@SamHH 我知道 mysql 的问题,但现在想问如何添加 js 和 css 代码来检索图像?
-
如果你知道问题出在 JS 和 CSS 上,你会更新问题只显示 PHP 的输出而不是 PHP 代码吗?
标签: javascript php jquery css