2012-05-17 3 views
2

누군가가 나를 도와 줄 수 있는지 궁금합니다.HTML 페이지에서 PHP 스크립트로 패스 변수

아래 코드는 사용자가 갤러리에서 이미지를 삭제할 수 있도록합니다.

전체 스크립트 마이너스 스타일링

본질적으로
<?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'스크립트에 전달할 수 있는지에 대한 지침을 제공한다.

많은 감사하고 HTML 페이지에있는 경우 종류 아약스 요청에 추가

+0

내 대답을 확인하십시오 .. 그게 뭘 원하는거야? – sujal

+0

안녕하세요 @ sujal, 내 게시물에 답장을하고 솔루션을 위해 시간을내어 주셔서 감사합니다. 귀하의 게시물에 대한 답변을 업데이트했습니다. – IRHM

답변

0

시도하여 PHP는

처럼 HTML 페이지에서 ID를 보내3210
$.ajax({ 
    url : 'delete.php?userid=2&locationid=4', 
    ........ 

그리고 PHP에서

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

당신은 사용자 ID를 얻고 싶은 경우에 동적으로 각 이미지에 대한 locationid.

FIRST; btn-delete class에 uid와 locid 속성을 추가합니다. PHP를 통해 반복하고 있다고 가정합니다.

LIKE ===> 스크립트에서 다음

<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 아이디 = $ (이) .attr ('ID');

+0

안녕하세요 @Sandy 프랭크, 내 게시물에 회신하는 시간을내어 주셔서 감사합니다. 불행히도 '현재 위치'의 '현재 사용자'에 대한 가치와 관련성 때문에 변경 될 수 있으므로이를 고려해야합니다. 친절한 점은 – IRHM

+0

은 "현재 위치의 '현재 사용자'에 대한 가치와 관련성이 무엇을 의미합니까? –

+0

안녕하세요 @Sandy Fark입니다. 이 사실을 분명히하지 않는 것에 대해 사과드립니다. 나는 이것에 아주 새롭다 그래서 나는 아마 완전히 이해하지 않는다, 그래서 오해하는 경우에 저를 정정하십시오. 귀하의 솔루션에서 당신은 ID를 보내는 것이 좋습니다,하지만 나는이 값들이 정적이고 각각의 사용자에 대해 수동으로 변경해야 할 것인가, 아니면이 값들이 자동으로 뽑혀 야하는지 생각하고 있습니다. 친절한 대답 – IRHM

1

에 관하여 :

{ image : img.attr('src'), userid: "VALUE", locationid: "VALUE"}, 
+0

안녕하세요 @ 아담, 내 게시물에 회신하는 시간을내어 주셔서 대단히 감사합니다. 당신은 내게 '값을 올바르게 가져 오는 중인지 보여주는 내 delete.php'파일에있는 방법이 제발 말해 줄래? 감사합니다 – IRHM

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'); 
       } 
      }); 

유형 추가 : 'JSON'과 삭제에 값을 게시 얻을.

$userid=$_POST['userid']; 
$locationid=$_POST['locationid']; 
+0

안녕하세요 @ sujal, 이것에 대해 많은 감사드립니다. 불행히도 해결책은 작동하지 않습니다. 슬프게도 내 onclick 이벤트가 더 이상 실제 이미지를 삭제하지 않습니다. 또한 PHP에 대해 비교적 익숙하지 않았으므로 물어볼 수는 있지만 용서해주십시오. 'delete.php'스크립트의 값을 에코하여 올바르게 뽑아 냈는지 보여주는 방법이 있습니까? 많은 감사와 친절 감사합니다. – IRHM