2

我想知道是否有人可以帮助我。

下面的代码允许用户从图库中删除图像。

完整的脚本减去样式

 <?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">&larr; 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>

本质上,用户单击删除图标,然后上面代码中调用的“delete.php”脚本从服务器中删除图像。这一切都很好。

我正在努力解决的是如何将两个变量值传递给“delete.php”脚本。它们是“userid”和“locationid”。

我尝试将以下内容添加到“delete.php”的开头:

<?php session_start(); 

$_SESSION['userid']=$_POST['userid'];
$_SESSION['locationid']=$_POST['locationid'];

但是这些值不会被结转。我怀疑这可能是因为表单“POST”操作被用于导航到另一个 HTML 页面,尽管我不是专家,所以我可能弄错了。

我已经阅读了大量内容并搜索了有关如何解决此问题的教程,但我没有找到任何似乎可以提出解决方案的内容。

我只是想知道是否有人可以看看这个,并提供一些关于如何将这两个值传递给我的“delete.php”脚本的指导。

非常感谢和亲切的问候

4

3 回答 3

1

如果它们在 html 页面中,请将它们添加到 ajax 请求中:

{ image : img.attr('src'),  userid: "VALUE", locationid: "VALUE"},
于 2012-05-17T12:18:18.050 回答
0
 var userid=$('#userid').val();
 var locationid=$('#locationid').val();
 $.ajax({
                url : 'delete.php',
                type : 'post',
                dataType :  'json',
                data : { image : img.attr('src'),  userid: userid, locationid: locationid},
    ,
                success : function(){
                alert('Deleting image... ');
                img.parent().fadeOut('slow');
                }
          });

添加 dataType : 'json' 并在 delete.php 中通过

$userid=$_POST['userid'];
$locationid=$_POST['locationid'];
于 2012-05-17T12:20:08.673 回答
0

尝试从您的 html 页面发送 id,例如

 $.ajax({
    url : 'delete.php?userid=2&locationid=4',
   ........

然后在 php

$uid=$_POST['userid'];
$locid=$_POST['locationid'];

如果您想为每个图像动态获取用户 ID 和位置 ID。

第一的; 在你 btn-delete 类中添加 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>

var id=$(this).attr('id');

于 2012-05-17T12:20:39.630 回答