2012-03-17 14 views
0

誰かが私を助けてくれるかどうか疑問に思う。XML '場所を選択'ステートメント

私はAurigmaの 'Image Uploader'ソフトウェアを使用して、ユーザーがXMLファイルを使って収集して取得した画像データを使用して作成したレコードの画像を追加したり表示できるようにしています。

私がまとめたページの1つは、ユーザーが個別にまたは「ファンシーボックス」スライドショーの一部として画像を見ることを可能にするギャラリーを作成するものです。このスクリプトを以下に示します。

<!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"> 
<?php 

    $galleryPath = 'UploadedFiles/'; 

    $thumbnailsPath = $galleryPath . 'Thumbnails/'; 

    $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR; 

    $descriptions = new DOMDocument('1.0'); 
    $descriptions->load($absGalleryPath . 'files.xml'); 
?> 
<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 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 type="text/javascript"> 

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

    </script> 
    <style type="text/css"> 
<!-- 
.style1 { 
    font-size: 14px; 
    margin-right: 110px; 
} 
.style4 {font-size: 12px} 
--> 
    </style> 
</head> 
<body style="font-family: Calibri; color: #505050; font-size: 9px; border-bottom-width: thin; margin-top: 5px; margin-left: -475px; margin-right: 1px; margin-bottom: -10px;"> 
<div align="right" class="style1"> <a href = "imagefolders.php" /> View Uploaded Images In Folder Structure <a/> &larr; View All Uploaded Images </div> 
    <form id="gallery" class="page"> 
    <div id="container"> 
    <div id="center"> 
     <div class="aB"> 
     <div class="aB-B"> 
      <?php if ('Uploaded files' != $current['title']) :?> 
      <?php endif;?> 
      <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'); 
          $folder = htmlentities($xmlFile->getAttribute('folder'), 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>      </li> 
         <li class="item"></li> 
         <p><span class="style4"><b>Image Description:</b> <?php echo htmlentities($xmlFile->getAttribute('description'));?> <br /> 
          <b>Image contained in folder:</b> <?php echo htmlentities($xmlFile->getAttribute('folder'));?> </span><br /> 
          <?php endfor; ?> 
          </li> 
        </p> 
        </ul> 
       </div> 
       </div> 
      </div> 
      </div> 
     </div> 
     </div> 
    </div> 
    </div> 
     <div class="aB-a">  </div> 
     </div> 
    </div> 
    </div> 
    </form> 
</body> 
</html> 

私は何をできるようにしたいと思いますが、今取得された画像を作るされ、ユーザーの特定、すなわち、ユーザAが自分の画像をのみ見ることができます。

この情報がmySQLデータベースから直接取得されている場合、私はPHP内で 'SELECT WHERE'ステートメントを使用して返されたレコードをフィルタリングできることを知っていますが、 ?

多くのおかげで、ユーザーが唯一の自分のアップロードした画像を見ることができる

+1

XPathは、XMLのためのクエリ言語です。それはあなたの後のことですか? http://php.net/manual/en/simplexmlelement.xpath.php – Adam

+1

を参照してください。あなたはXPathの後にいます。 XMLの関連部分を表示して、クエリの条件を説明してください。また、以前に何度も回答があったので、検索機能を使用してください。チュートリアルについてはhttp://schlitt.info/opensource/blog/0704_xpath.htmlを参照してください。 – Gordon

+0

[PHPで属性ごとにXMLノードを選択](http://stackoverflow.com/questions/9252928/select-xml-node-by-attribute-in-php) – Gordon

答えて

1

は、このような単純な作業ではありません。画像が公開アクセス可能なフォルダに保存されている場合、誰でもブラウザを使用して画像を見ることができます。ファイルシステム上の各ユーザーの新しいfolerを作成し、 読み取りを変更するデータベースではなく、ファイルシステム内の画像、

  • を格納

    1. 次のようないくつかの選択肢があり、これを達成するために

      各フォルダのパーミッションを書き込み、または

    2. Webルートの外に画像を保存し、

      研つまりPHPを使用して画像 を取得画像へのリンクを提供しています。自動的に適切なヘッダーを提供するcgi スクリプトへのリンクを提供し、画像の内容を にします。例えば

      :?image.php sample.jpg

      あなたは、リンクの一部として(例えば セッションIDを渡す)、彼らがすでに認証されていることを確認することができます。

      これはヘッダーの一部であるため、画像データは に従うことができます。

      <?php 
      
      $file = basename(urldecode($_GET['file'])); 
      $fileDir = '/path/to/files/'; 
      
      if (file_exists($fileDir . $file)) 
      { 
          //perform some authorisation check 
          ... 
          ... 
      
          // Note: You should probably do some more checks 
          // on the filetype, size, etc. 
          $contents = file_get_contents($fileDir . $file); 
      
          // Note: You should probably implement some kind 
          // of check on filetype 
          header('Content-type: image/jpeg'); 
      
          echo $contents; 
      } 
      
      ?> 
      
  • +0

    OPの問題は厳密にXMLファイルから特定の要素を読み込むことだと思います。 – Gordon

    +0

    これは、他人が自分のイメージではないイメージを見ることができるという問題を必ずしも解決するものではありません。画像が一般にアクセス可能なフォルダに保存されている場合は、ブラウザを使用して画像をブラウズできます。 –

    +0

    "必然" /> "あなたがあまりにも多くの仮定をしている;) – Gordon

    関連する問題