2012-03-29 10 views
1

誰かが私を喜ばせることができるかどうか疑問に思います。ファイル名として 'Username'を保存します。

私はAurigmaのImage Uploaderを使用しています。アップロードした画像を保存するために、このスクリプトをまとめました。私がやりたいのは何

<?php 

//This variable specifies relative path to the folder, where the gallery with uploaded files is located. 
//Do not forget about the slash in the end of the folder name. 
$galleryPath = 'UploadedFiles/'; 

require_once 'Includes/gallery_helper.php'; 

require_once 'ImageUploaderPHP/UploadHandler.class.php'; 

/** 
* FileUploaded callback function 
* @param $uploadedFile UploadedFile 
*/ 
function onFileUploaded($uploadedFile) { 

    $packageFields = $uploadedFile->getPackage()->getPackageFields(); 
    $userid = $packageFields["userid"]; 
    $locationid= $packageFields["locationid"]; 

    global $galleryPath; 

    $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR; 
    $absThumbnailsPath = $absGalleryPath . 'Thumbnails' . DIRECTORY_SEPARATOR; 

    if ($uploadedFile->getPackage()->getPackageIndex() == 0 && $uploadedFile->getIndex() == 0) { 
    initGallery($absGalleryPath, $absThumbnailsPath, FALSE); 
    } 

    $dirName = $_POST['folder']; 
    $dirName = preg_replace('/[^a-z0-9_\-\.()\[\]{}]/i', '_', $dirName); 
    if (!is_dir($absGalleryPath . $dirName)) { 
    mkdir($absGalleryPath . $dirName, 0777); 
    } 

    $path = rtrim($dirName, '/\\') . '/'; 

    $originalFileName = $uploadedFile->getSourceName(); 

    $files = $uploadedFile->getConvertedFiles(); 

    // save converter 1 

    $sourceFileName = getSafeFileName($absGalleryPath, $originalFileName); 
    $sourceFile = $files[0]; 
    /* @var $sourceFile ConvertedFile */ 
    if ($sourceFile) { 
    $sourceFile->moveTo($absGalleryPath . $sourceFileName); 
    } 

    // save converter 2 

    $thumbnailFileName = getSafeFileName($absThumbnailsPath, $originalFileName); 
    $thumbnailFile = $files[1]; 
    /* @var $thumbnailFile ConvertedFile */ 
    if ($thumbnailFile) { 
    $thumbnailFile->moveTo($absThumbnailsPath . $thumbnailFileName); 
    } 

    //Load XML file which will keep information about files (image dimensions, description, etc). 
    //XML is used solely for brevity. In real-life application most likely you will use database instead. 
    $descriptions = new DOMDocument('1.0', 'utf-8'); 
    $descriptions->load($absGalleryPath . 'files.xml'); 

    //Save file info. 
    $xmlFile = $descriptions->createElement('file'); 
    $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()); 
    //Add additional fields 
    $xmlFile->setAttribute('userid', $userid); 
    $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(); 
?> 

は、ファイル名のfiles要素を交換し、usernameと交換しているので、各保存したフォルダと関連ファイルは、各ユーザーにINDENTIFIEDすることができます。

私は、このスクリプトは、私は、これは$descriptions->save($absGalleryPath . 'files.xml');を変更する必要がある行であることを言うには右だと思う

から保存し、フォームにユーザー名テキストフィールドを追加しました。

多くの試みの中で私はこれを$descriptions->save($absGalleryPath . '$username.xml$descriptions->save($absGalleryPath . $username '.xmlに変更しようとしましたが、これらのどれもうまくいきませんでしたので、私は何を変更する必要があるのか​​よくわかりません。

私はちょうど誰かがこれを見て、私がどこに間違っているのかを教えてもらえるかどうか疑問に思った。

感謝

答えて

0

'$のusername.xmlは、' あなたは "$のusername.xml" を使用する必要があり、$ username.xmlとして解釈されます。文字列の中で変数を使用することを一重引用符で囲みます。

あなたが作っているように、あなたは「/」のような「特殊文字」を含むことはできません。おそらくあなたは、誰かがユーザー名の一部である "/"を止めるというルールを持っていれば、問題はありません。

+0

時間をかけて私を助けてくれてありがとう。敬具。 – IRHM

関連する問題