将变量从HTML页面传递到PHP脚本
不知是否有人能帮助我 下面的代码允许用户从图库中删除图像 完整脚本减去样式将变量从HTML页面传递到PHP脚本,php,variables,global-variables,Php,Variables,Global Variables,不知是否有人能帮助我 下面的代码允许用户从图库中删除图像 完整脚本减去样式 <?php session_start(); $_SESSION['userid']=$_POST['userid']; $_SESSION['locationid']=$_POST['locationid']; //echo $_SESSION['userid']; //echo $_SESSION['locationid']; ?> <?php $galleryPath = 'Up
<?php session_start();
$_SESSION['userid']=$_POST['userid'];
$_SESSION['locationid']=$_POST['locationid'];
//echo $_SESSION['userid'];
//echo $_SESSION['locationid'];
?>
<?php
$galleryPath = 'UploadedFiles/' . $_SESSION['userid'] . '/' . $_SESSION['locationid'] . '/';
$absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR;
$descriptions = new DOMDocument('1.0');
$descriptions->load($absGalleryPath . 'files.xml');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=0.3">
<title>Galleria Twelve Theme</title>
<style>
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery-ui-1.8.19.custom.min.js"></script>
<script src="galleria/galleria-1.2.7.min.js"></script>
<script src="galleria/themes/twelve/galleria.twelve.min.js"></script>
<script src="galleria/plugins/history/galleria.history.min.js"></script>
<link rel="stylesheet" href="galleria/themes/twelve/galleria.twelve.css">
<style>
.galleria-thumbnails .btn-delete {
display: block; /* Or just use a div instead of a span*/
position: absolute; bottom : 0px; /*align at the bottom*/
width: 80px;
height: 17px;
cursor: pointer;
background: url(trash8.gif) no-repeat bottom; }
</style>
<script type="text/javascript">
Galleria.ready(function() {
this.$('thumblink').click();
$(".galleria-image").append(
"<span class='btn-delete ui-icon ui-icon-trash'></span>");
$(".btn-delete").live("click", function(){
// you do not need to find img and then src... just use id of image
var img = $(this).closest(".galleria-image").find("img");
var userid=$(".hiddenvals").attr('userid');
var locationid=$(".hiddenvals").attr('locationid');
// send the AJAX request
$.ajax({
url : 'delete3.php?userid='+userid+'&locationid='+locationid,
type : 'post',
data : { image : img.attr('src') },
success : function(){
alert('Deleting image... ');
img.parent().fadeOut('slow');
}
});
return false;
});
});
</script>
</head>
<body>
<ul id="navigation">
<li class="left">
<div align="center"><a href="javascript:document.viewimages.submit()" class="style2">← Add Images</a></div>
</li>
</ul>
<form id="viewimages" name="viewimages" class="page" action="index.php" method="post"> <input name="userid" class="hiddenvals" type="hidden" value="<?php echo $_SESSION['userid']; ?>"> <input name="locationid" class="hiddenvals" type="hidden" value="<?php echo $_SESSION['locationid']; ?>"></form>
<div class="content">
<h1>Galleria Twelve Theme</h1>
<p>Demonstrating a simple example.</p>
<!-- Adding gallery images. We use resized thumbnails here for better performance, but it’s not necessary -->
<div id="galleria">
<?php for ($i = 0; $i < $descriptions->documentElement->childNodes->length; $i++) :
$xmlFile = $descriptions->documentElement->childNodes->item($i);
$name = htmlentities($xmlFile->getAttribute('originalname'), ENT_COMPAT, 'UTF-8');
$description = htmlentities($xmlFile->getAttribute('description'), ENT_COMPAT, 'UTF-8');
$source = $galleryPath . rawurlencode($xmlFile->getAttribute('source'));
?>
<a href="<?php echo $source; ?>"><img data-title="<b>Image Name: </b> <?php echo $name; ?>" data-description="<b>Description:</b> <?php echo $description; ?>" src="<?php echo $source; ?>"></a>
<?php endfor; ?>
</body>
</html>
十二主题画廊
.galleria缩略图。btn删除{
显示:block;/*或仅使用div而不是span*/
位置:绝对;底部:0px;/*在底部对齐*/
宽度:80px;
高度:17px;
光标:指针;
背景:url(trash8.gif)无重复底部;}
Galleria.ready(函数(){
这是。$('thumblink')。单击();
$(“.galleria image”)。附加(
"");
$(“.btn delete”).live(“单击”,函数(){
//您不需要找到img,然后src…只需使用图像的id
var img=$(this).closest(“.galleria image”).find(“img”);
var userid=$(“.hiddenvals”).attr('userid');
var locationid=$(“.hiddenvals”).attr('locationid');
//发送AJAX请求
$.ajax({
url:'delete3.php?userid='+userid+'&locationid='+locationid,
键入:“post”,
数据:{image:img.attr('src')},
成功:函数(){
警报('删除图像…');
img.parent().fadeOut('slow');
}
});
返回false;
});
});
-
documentElement->childNodes->item($i);
$name=htmlentities($xmlFile->getAttribute('originalname'),ENT_COMPAT,'UTF-8');
$description=htmlentities($xmlFile->getAttribute('description'),ENT_COMPAT,'UTF-8');
$source=$galleryPath。rawurlencode($xmlFile->getAttribute('source'));
?>
本质上,用户单击一个delete图标,然后上面代码中调用的“delete.php”脚本从服务器上删除图像。这一切都很好
我正在努力解决的是如何将两个变量值传递给'delete.php'脚本。它们是“userid”和“locationid”
我已尝试将以下内容添加到“delete.php”的开头:
<?php session_start();
$_SESSION['userid']=$_POST['userid'];
$_SESSION['locationid']=$_POST['locationid'];
如果它们在html页面中,请将它们添加到ajax请求中:
{ image : img.attr('src'), userid: "VALUE", locationid: "VALUE"},
在delete.php中添加数据类型:“json”并通过
$userid=$_POST['userid'];
$locationid=$_POST['locationid'];
尝试从html页面发送ID,如
$.ajax({
url : 'delete.php?userid=2&locationid=4',
........
然后在php中
$uid=$_POST['userid'];
$locid=$_POST['locationid'];
如果您想为每个图像动态获取userid和locationid
第一,;在您的btn删除类中添加uid和locid属性。我想您正在循环使用PHP
喜欢==>
<input type="button" class="btn-delete" uid="2" locid="5">
然后在你的剧本里
<script type="text/javascript">
Galleria.ready(function() {
this.$('thumblink').click();
$(".galleria-image").append(
"<span class='btn-delete ui-icon ui-icon-trash'></span>");
$(".btn-delete").live("click", function(){
// you do not need to find img and then src... just use id of image
var img = $(this).closest(".galleria-image").find("img");
var uid=$(this).attr('uid');
var locid=$(this).attr('locid');
// send the AJAX request
$.ajax({
url : 'delete.php?userid='+uid+'&locationid='+locid,
type : 'post',
data : { image : img.attr('src') },
success : function(){
alert('Deleting image... ');
img.parent().fadeOut('slow');
}
});
return false;
});
});
</script>
Galleria.ready(函数(){
这是。$('thumblink')。单击();
$(“.galleria image”)。附加(
"");
$(“.btn delete”).live(“单击”,函数(){
//您不需要找到img,然后src…只需使用图像的id
var img=$(this).closest(“.galleria image”).find(“img”);
var uid=$(this.attr('uid');
var locid=$(this.attr('locid');
//发送AJAX请求
$.ajax({
url:'delete.php?userid='+uid+'&locationid='+locid,
键入:“post”,
数据:{image:img.attr('src')},
成功:函数(){
警报('删除图像…');
img.parent().fadeOut('slow');
}
});
返回false;
});
});
var id=$(this.attr('id') 检查我的答案。。这就是你想要的吗?嗨@sujal,非常感谢你花时间回复我的帖子,感谢你提供的解决方案,我正在测试。我已经在你的帖子下更新了我的答案。嗨@sujal,非常感谢。不幸的是,这个解决方案不起作用。不幸的是,我的onclick事件不再删除物理映像。另外,请原谅我的提问,因为我对PHP比较陌生,但是你能告诉我吗。有没有一种方法可以让我回显'delete.php'脚本中的值,以表明它们被正确地拉过?非常感谢,谢谢你花时间回复我的帖子。不幸的是,“当前位置”中的“当前用户”的值和相关性会发生变化,我需要考虑这一点。Kind Regards您所说的“当前位置”中的“当前用户”的值和相关性会发生变化是什么意思?嗨@Sandy Fark。我很抱歉没有说得更清楚。我对这个很陌生,所以可能我不完全理解,所以如果我误解了,请纠正我。在您的解决方案中,您建议发送id,但我是否认为这些值是静态的,必须为每个用户手动更改,或者这些值是自动通过的?我刚刚添加了解决方案,如果你发现困难,请告诉我。嗨@Sandy Fark。非常感谢。请原谅我的提问,但是由于我的“userid”和“locationid”值位于两个隐藏的文本字段中,我是否可以省略对按钮的任何更改,但仍然在url中显示这些字段:例如,url:'delete.php?userid='+uid+'&locationid='+locid,正如您在更新的解决方案中所显示的那样?善良的regardsHi@Adam,非常感谢您抽出时间回复我的帖子。你能告诉我在我的'delete.php'文件中有没有一种方法可以显示这些值被正确地提取出来?问候
<script type="text/javascript">
Galleria.ready(function() {
this.$('thumblink').click();
$(".galleria-image").append(
"<span class='btn-delete ui-icon ui-icon-trash'></span>");
$(".btn-delete").live("click", function(){
// you do not need to find img and then src... just use id of image
var img = $(this).closest(".galleria-image").find("img");
var uid=$(this).attr('uid');
var locid=$(this).attr('locid');
// send the AJAX request
$.ajax({
url : 'delete.php?userid='+uid+'&locationid='+locid,
type : 'post',
data : { image : img.attr('src') },
success : function(){
alert('Deleting image... ');
img.parent().fadeOut('slow');
}
});
return false;
});
});
</script>