我想知道是否有人能夠幫助我請。使用字段值的文件路徑
我試圖加載具有以下文件路徑的XML文件:
/UploadedFiles/username/location/files.xml
我一直在嘗試了一段時間做的,就是用兩種形式字段的值,「用戶名」和'位置'並將它們合併到文件路徑中,但我似乎無法得到正確的結果。
我只是想知道是否某個人可能會告訴我如何獲取這些值並在文件路徑中使用它們。
非常感謝
POST修訂
我以爲我可以通過簡單地改變文件的路徑,因此,我原來的職位解決我的問題,但我擔心我缺乏的PHP知識,讓我下來,我懷疑我的代碼中存在的問題更深。
請在下面找到更多的細節。
下面的腳本顯示了我最初如何保存圖像。
'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();
?>
該腳本產生以下文件結構:
UPLOADEDFILES(預先存在的文件夾)
- '用戶名'(子文件夾包含'位置'文件夾)
- 'location'(包含原始圖像的子文件夾'文件s.xml」和 '縮略圖' 文件夾中)
- '包含原始圖像的縮略圖的縮略圖'(子文件夾)
NB。'用戶名'和'位置文件夾名稱是從當前用戶和位置值派生而來的。
然後我來創建圖像庫來解決我的問題。
下面的代碼是我最初的'gallery.php'腳本。我需要改變腳本的頂部PHP部分到新的文件夾結構相匹配,即UploadedFiles/'username'/'location'/Thumbnails
和UploadedFiles/'username'/'location'.files.xml
「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/> ← 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>
我承認自己在如何解決這個真正的損失,我不知道是我的'gallery.php'腳本需要更改還是我的'upload.php'
任何幫助都會非常感激地收到。
親切的問候
如果我正確理解你內,普通的舊串聯會的工作。你有什麼嘗試? – Rick 2012-04-14 15:43:14
您可以編輯此問題以添加更多詳細信息。當然不改變話題。 – Starx 2012-04-15 13:27:48
Hi @Starx,只是爲了讓你知道我已更新我的文章。親切的問候 – IRHM 2012-04-15 14:43:27