누군가가 나를 도와 줄 수 있는지 궁금합니다.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">← 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 페이지에있는 경우 종류 아약스 요청에 추가
내 대답을 확인하십시오 .. 그게 뭘 원하는거야? – sujal
안녕하세요 @ sujal, 내 게시물에 답장을하고 솔루션을 위해 시간을내어 주셔서 감사합니다. 귀하의 게시물에 대한 답변을 업데이트했습니다. – IRHM