2012-04-25 6 views
0

나는 누군가가 나를 도울 수 있는지 궁금해.이미지 삭제 라디오 버튼

아래 이미지 갤러리를 만드는 스크립트를 작성했습니다.

<?php 

    if (isset($_POST['del'])) 
     $originalname = intval($_POST['del']); 

     $file = 'UploadedFiles/' . $_SESSION['username'] . '/' . $_SESSION['locationid'] . '/' '$originalname'; 
if (!unlink($file)) 
    { 
    echo ("Error deleting $file"); 
    } 
else 
    { 
    echo ("Deleted $file"); 
    } 
?> 

<?php 

    $galleryPath = 'UploadedFiles/' . $_SESSION['username'] . '/' . $_SESSION['locationid'] . '/'; 

    $thumbnailsPath = $galleryPath . 'Thumbnails/'; 

    $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR; 

    $descriptions = new DOMDocument('1.0'); 
    $descriptions->load($absGalleryPath . 'files.xml'); 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>Gallery</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <link href="Libraries/fancybox/jquery.fancybox-1.3.1.css" rel="stylesheet" type="text/css" /> 
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/base/jquery-ui.css" type="text/css" media="all" /> 
    <link href="Styles/style.css" rel="stylesheet" type="text/css" /> 
    <!--[if IE]> 
    <link href="Styles/ie.css" rel="stylesheet" type="text/css" /> 
    <![endif]--> 
    <script src="Libraries/jquery/jquery-1.4.3.min.js" type="text/javascript"></script> 
    <script src="Libraries/fancybox/jquery.fancybox-1.3.1.pack.js" type="text/javascript"></script> 
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js" type="text/javascript"></script>   
    <script type="text/javascript"> 

    $(function() { $('a.fancybox').fancybox(); }); 

    </script> 
    <style type="text/css"> 
<!-- 
.style1 { 
    font-size: 14px; 
    margin-right: 110px; 
} 
.style4 {font-size: 12px} 
--> 
    </style> 
    <script type="text/javascript"> 
    function showdialog() { 
     // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore! 
     $("#dialog:ui-dialog").dialog("destroy"); 

     $("#dialog-confirm").dialog({ 
      resizable: false, 
      height:160, 
      modal: false, 
      buttons: { 
       "Delete image": function() { 
        $(this).dialog("close"); 
       }, 
       Cancel: function() { 
        $(this).dialog("close"); 
       } 
      } 
     }); 
    }; 
    </script> 


</head> 
<body style="font-family: Calibri; color: #505050; font-size: 9px; border-bottom-width: thin; margin-top: 5px; margin-left: -476px; margin-right: 1px; margin-bottom: -10px;"> 
<div align="right" class="style1"> <a href = "javascript:document.gallery.submit()"/> Add Images <a/> &larr; View Uploaded Images </div> 
    <form id="gallery" name="gallery" class="page" action="index.php" method="post"> 
    <div id="container"> 
    <div id="center"> 
     <div class="aB"> 
     <div class="aB-B"> 
      <?php if ('Uploaded files' != $current['title']) :?> 
      <?php endif;?> 
      <input name="deleteimage" type="button" value="Delete Selected Image" onclick="showdialog()" /> 
      <div class="demo"> 
      <div class="inner"> 
       <div class="container"> 
       <div class="gallery"> 
        <ul class="gallery-image-list"> 
        <?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')); 
          $thumbnail = $thumbnailsPath . rawurlencode($xmlFile->getAttribute('thumbnail')); 
        ?> 
        <li class="item"> 
         <a class="fancybox" target="_blank" rel="original" href="<?php echo $source; ?>"><img class="preview" 
         alt="<?php echo $name; ?>" src="<?php echo $thumbnail; ?>" /></a><?php echo "<input type='radio' name='del' value='{$originalname}' />"?></li> 
         <p><span class="style4"><b>Image Name:</b> <?php echo htmlentities($xmlFile->getAttribute('originalname'));?> <br /> 
          <b>Image Description:</b> <?php echo htmlentities($xmlFile->getAttribute('description'));?> </span><br /> 
          <?php endfor; ?> 
          </li> 
         </p> 
        </ul> 
       </div> 
       </div> 
      </div> 

    </div> 
    <div id="dialog-confirm" title="Delete This Image?"> 
    <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>This image will be permanently deleted and cannot be recovered. Are you sure?</p> 
</div> 
    </div> 
     <div class="aB-a">  </div> 
     </div> 
    </div> 
    </div> 
    </form> 
</body> 
</html> 
각 이미지에 대하여

, 내 코드 줄에 나타나는 : alt="<?php echo $name; ?>" src="<?php echo $thumbnail; ?>" /></a><?php echo "<input type='radio' name='del' value='{$originalname}' />"?></li> 나는 라디오 버튼을 추가했습니다. 라디오 버튼시

가 선택되고,하고 '선택한 이미지를 삭제'버튼을 나는 이미지가이 파일 경로에서 삭제하고 싶은 클릭하고 여기

$galleryPath = 'UploadedFiles/' . $_SESSION['username'] . '/' . $_SESSION['locationid'] . '/'; 

과 : 나는 '$thumbnailsPath = $galleryPath . 'Thumbnails/';

PHP와는 훌륭하지 않지만 몇 가지 연구를 해본 결과 '링크 해제'명령을 사용해야한다고 생각합니다. 그래서 처음에는 하나의 파일 경로 만 사용하여이 절차를 작성하려고했습니다. 라디오 버튼을 선택하여 올바른 Dialog Confirmation 메시지를 표시 할 수는 있지만 불행히도 이미지를 삭제하지는 않습니다. 문제가있는 곳을 잘 모르겠습니다.

나는 누군가가 이걸 좀 봐 주 었는지 의심스러워하고 내가 어디로 잘못 갔는지 알려주려고했다.

많은 감사와 관련

답변

0

당신이 링크 해제 명령에 이미지에 대한 올바른 경로를 전달하는 알고 있다면, PHP를 실행하는 사용자 계정이 파일에 쓰기 권한이 없습니다 수 있습니다.

E_WARNING 수준에서 오류를 켜고 테스트 스크립트를 실행하여 경고 메시지가 표시되는지 확인할 수 있습니다. 또한 unlink의 반환 값을 테스트해야합니다. 실패하면 FALSE를 반환합니다.

+0

안녕하세요, 회신 해 주셔서 감사합니다. 내가 가진 문제는 오류 메시지가 나타나지 않아서 권한 문제가 아닌 코드가 원인이라는 것을 알 수 있습니다. 하지만 PHP에 익숙하지 않기 때문에 코드에 문제가 있는지 확실하지 않습니다. 이 코드가 정확한지, 아니면 코드가 맞는지 아닌지에 대해 감사하지만, 정말 확인을 원했습니다. 친절 관련 – IRHM

+0

이 줄의 구문이 잘못되었습니다. 마지막 두 문자열을 결합하는 점이 누락되었습니다 : $ file = 'UploadedFiles /'. $ _SESSION [ 'username']. '/'. $ _SESSION [ 'locationid']. '/' '$ originalname'; 대 $ file = 'UploadedFiles /'. $ _SESSION [ 'username']. '/'. $ _SESSION [ 'locationid']. '/'. '$ originalname'; 차이점을 확인 하시겠습니까? – gcochard

+0

안녕하세요 @ 그렉, 많은 것에 대해 감사드립니다. 무슨 뜻인지 알 겠어. 나는 변화를 만들거야. 감사합니다 – IRHM