2012-04-25 8 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に秀でていませんが、いくつかの研究を行いました。私は 'unlink'コマンドを使用する必要があると私は信じています。だから私は最初に1つのファイルパスだけを使ってこの手続きを書こうとしています。ラジオボタンを選択して正しいDialog Confirmationメッセージを表示することはできますが、残念ながら画像は削除されません。問題がどこにあるのかはわかりません。

私はちょうど誰かがこれを見て、私が間違っていた場所を教えてくれるかどうか疑問に思いましたか?

多くのおかげに関して

答えて

0

あなたがリンク解除コマンドに画像への正しいパスを渡している知っていれば、PHPを実行しているユーザーアカウントがファイルに書き込み権限を持っていない可能です。

E_WARNINGレベルでエラーをオンにしてから、テストスクリプトを実行して警告が表示されるかどうかを確認することができます。 unlinkの戻り値もテストする必要があります。これは、失敗した場合にFALSEを戻すためです。

+0

こんにちは、お返事ありがとうございます。私が持っている問題は、エラーメッセージが表示されず、許可の問題ではなくコードが原因であることが示唆される場合があります。しかし、私は少しPHPのため、自分のコードに問題があるかどうかはわかりません。私は本当に確認が欲しいと思っていましたが、これはちょうどハイパーテラルかもしれない、私のコードが正しいかどうか分かりましたか?種類: – IRHM

+0

この行の構文が間違っています。最後の2つの文字列を結合するドットがありません: $ file = 'UploadedFiles /'。 $ _SESSION ['username']。 '/'。 $ _SESSION ['locationid']。 '/' '$ originalname'; 対 $ file = 'UploadedFiles /'。 $ _SESSION ['username']。 '/'。 $ _SESSION ['locationid']。 '/'。 '$ originalname'; 違いを確認しますか? – gcochard

+0

こんにちは@グレッグ、これは多くのありがとう。私はあなたが何を意味するかを見ます。私は変更を行います。親切には – IRHM

関連する問題