2012-04-14 7 views
0

誰かが私を助けてくれるかどうか疑問に思う。フィールド値をファイルパスに使用する

私は、次のファイルパスを使用してXMLファイルをロードしようとしています:

/UploadedFiles/username/location/files.xml 

私はいくつかの時間のためにやろうとしていたもの、二つの形式フィールドの値を使用することで、「ユーザ名」と '場所'とファイルパスにそれらを組み込むが、私はちょうどこの権利を得るように見えることはできません。

私は、誰かがおそらく私がこれらの値をどのようにとってファイルパスで使用するか教えてくれるかどうか疑問に思っただけです。私を失望させるように私は私のオリジナルのポストそれゆえ、私は単純にファイルパスを変更することで、私の問題を解決できると思ったが、私はPHPの知識の私の不足を恐れ

感謝

POST改正

と私の問題は、自分のコードの中で深いと思う。

以下でさらに詳しく説明します。

以下のスクリプトは、最初に画像を保存する方法を示しています。

UploadedFiles(プリ既存のフォルダ)

  • 'ユーザ名'(サブフォルダ含む ':

    'upload.php'

    <?php 
    require_once 'Includes/gallery_helper.php'; 
    require_once 'ImageUploaderPHP/UploadHandler.class.php'; 
    $galleryPath = 'UploadedFiles/'; 
    
    function onFileUploaded($uploadedFile) { 
        global $galleryPath; 
    
        $packageFields = $uploadedFile->getPackage()->getPackageFields(); 
        $username=$packageFields["username"]; 
        $locationid=$packageFields["locationid"]; 
        $username = preg_replace('/[^a-z0-9_\-\.()\[\]{}]/i', '_', $_POST['username']); 
        $location = preg_replace('/[^a-z0-9_\-\.()\[\]{}]/i', '_', $_POST['locationid']); 
        $dirName = preg_replace('/[^a-z0-9_\-\.()\[\]{}]/i', '_', $_POST['folder']); 
    
        $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR . $username . DIRECTORY_SEPARATOR . $location . DIRECTORY_SEPARATOR; 
        $absThumbnailsPath = $absGalleryPath . 'Thumbnails' . DIRECTORY_SEPARATOR; 
    
    
        if (!is_dir($absGalleryPath)) mkdir($absGalleryPath, 0777, true); 
        chmod($absGalleryPath, 0777); 
        if (!is_dir($absGalleryPath . $dirName)) mkdir($absGalleryPath . $dirName, 0777, true); 
        chmod($absGalleryPath . $dirName, 0777); 
    
        if ($uploadedFile->getPackage()->getPackageIndex() == 0 && $uploadedFile->getIndex() == 0) 
        initGallery($absGalleryPath, $absThumbnailsPath, FALSE); 
    
        $originalFileName = $uploadedFile->getSourceName(); 
        $files = $uploadedFile->getConvertedFiles(); 
        $sourceFileName = getSafeFileName($absGalleryPath, $originalFileName); 
        $sourceFile = $files[0]; 
    
        if ($sourceFile) $sourceFile->moveTo($absGalleryPath . $sourceFileName); 
        $thumbnailFileName = getSafeFileName($absThumbnailsPath, $originalFileName); 
        $thumbnailFile = $files[1]; 
        if ($thumbnailFile) $thumbnailFile->moveTo($absThumbnailsPath . $thumbnailFileName); 
    
        $descriptions = new DOMDocument('1.0', 'utf-8'); 
        $descriptions->load($absGalleryPath . 'files.xml'); 
    
        $xmlFile = $descriptions->createElement('file'); 
        // <-- please check the following line 
        $xmlFile->setAttribute('name', $_POST['folder'] . '/' . $originalFileName); 
        $xmlFile->setAttribute('source', $sourceFileName); 
        $xmlFile->setAttribute('size', $uploadedFile->getSourceSize()); 
        $xmlFile->setAttribute('originalname', $originalFileName); 
        $xmlFile->setAttribute('thumbnail', $thumbnailFileName); 
        $xmlFile->setAttribute('description', $uploadedFile->getDescription()); 
        $xmlFile->setAttribute('username', $username); 
        $xmlFile->setAttribute('locationid', $locationid); 
        $xmlFile->setAttribute('folder', $dirName); 
    
    
        $descriptions->documentElement->appendChild($xmlFile); 
        $descriptions->save($absGalleryPath . 'files.xml'); 
    } 
    
    $uh = new UploadHandler(); 
    $uh->setFileUploadedCallback('onFileUploaded'); 
    $uh->processRequest(); 
    ?> 
    

    このスクリプトは、次のファイル構造を生成します場所 'フォルダ)

  • '場所 '(元の画像を含むサブフォルダ、'ファイルs.xml」と 'サムネイル' フォルダ)
  • '原画像のサムネイル'(サブフォルダを含むサムネイル)

NB。 'username'と 'location folder'の名前は、現在のユーザーと場所の値から得られます。

私は画像ギャラリーを作成して問題を解決します。

以下のコードは私の最初の 'gallery.php'スクリプトです。私はこの問題を解決する方法で、実際の損失であることを認める

<?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: -476px; 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"> 
      <input name="username" type="text" id="username" value="IRHM73" /> 
      <input name="locationid" type="text" id="locationid" value="1" /> 
      <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> 
         <p><span class="style4"><b>Image Description:</b> <?php echo htmlentities($xmlFile->getAttribute('description'));?> <br /> 
          <b>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> 

UploadedFiles/'username'/'location'/ThumbnailsUploadedFiles/'username'/'location'.files.xml

すなわち、新しいフォルダ構造に一致するようにスクリプトの先頭PHPセクションを変更する必要がある「gallery.php」私はそれが私の 'gallery.php'スクリプトか、私の 'upload.php'なのかどうかはわかりません。

ご協力いただきありがとうございます。usernamelocation

種類はOK、あなたがこの値を持っているとしましょう

+0

以内にあります。何を試しましたか? – Rick

+0

この質問を編集して詳細を追加することができます。もちろんトピックを変更することなく。 – Starx

+0

こんにちは@Starx、私は自分の投稿を更新したことをお知らせします。種類について – IRHM

答えて

1

について。応答スクリプト内の(フォームのアクションを受け取る1)(私はあなたの質問の権利を取得する場合)

次に、これを試してみてください。

<?php 

    $username = $_GET['username']; 
    $location = $_GET['location']; 

    $filepath = "/UploadedFiles/$username/$location/files.xml"; 

?> 

ヒント(文字列を連結する2つの方法を)

$filepath = "/UploadedFiles/$username/$location/files.xml"; 

OR

$filepath = "/UploadedFiles/".$username."/".$location."/files.xml"; 
+0

こんにちは、これは多くのありがとう。残念ながら、私はこれを動作させることができませんでした。しかし、私の元の投稿を見て、私は十分な詳細を提供していないと私はこれを謝罪します。私は今これについてもっと詳しく述べました。良いと思います。 – IRHM

1

これは、あなたのフォームでポストまたは取得方法を使用しているかどうかに関係なく機能します。入力テキストhtml要素のフィールド名のユーザー名と場所を選択してください。

$filepath = "/UploadedFiles/{$_REQUEST['username']}/{$_REQUEST['location']}/files.xml" 
+0

こんにちは、ありがとうございました。残念ながら、私はこれを動作させることができませんでしたが、私はエラーを受け取りませんでした。しかし、私のスクリプトとあなたのコードではなく、PHPの知識が不足していると思います。オリジナルの投稿には十分な詳細が含まれていないと感じています。私は今これを追加しました。良いと思います – IRHM

1

あなたは変数としてそれらを定義する必要があり、私はあなたが正しく、定期的に古い連結が働くだろう理解していた場合は、文字列

$username = "user1"; 
$location = "userlocation1"; 

$url = "/UploadedFiles/$username/$location/files.xml"; 

//Next you might want to verify the location 

if(is_file($url)) { 
    //do your operation.... 
} 
+0

こんにちは、これは多くのありがとう。残念ながら、私はこれを動作させることができませんでしたが、私の元の投稿を見て、私は十分な詳細を提供していなかった、私はこれを謝罪し、私は新しい投稿を提起した。親切には – IRHM

+0

@IRHM、あなたの投稿はどちらですか? – Starx

+0

ご返信いただきありがとうございます、私は数分で投稿を修正します。敬具 – IRHM

関連する問題