Php 对文件路径使用字段值
不知是否有人能帮助我 我正在尝试加载具有以下文件路径的xml文件:Php 对文件路径使用字段值,php,Php,不知是否有人能帮助我 我正在尝试加载具有以下文件路径的xml文件: /UploadedFiles/username/location/files.xml 一段时间以来,我一直在尝试使用两个表单字段“username”和“location”的值,并将它们合并到文件路径中,但我似乎无法做到这一点 我只是想知道是否有人可以告诉我如何获取这些值并在文件路径中使用它们 非常感谢 修订后 我认为我可以通过简单地更改文件路径来解决我的问题,因此我发表了我的原始文章,但我担心我缺乏PHP知识会让我失望,我怀疑
/UploadedFiles/username/location/files.xml
一段时间以来,我一直在尝试使用两个表单字段“username”和“location”的值,并将它们合并到文件路径中,但我似乎无法做到这一点
我只是想知道是否有人可以告诉我如何获取这些值并在文件路径中使用它们
非常感谢
修订后
我认为我可以通过简单地更改文件路径来解决我的问题,因此我发表了我的原始文章,但我担心我缺乏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();
?>
我承认我对如何解决这个问题感到非常困惑,我不知道是我的“gallery.php”脚本需要更改,还是我的“upload.php”
任何帮助都会得到感激
亲切问候好的,假设您有以下值:
用户名
,位置
然后,(如果我答对了你的问题)在响应脚本(接收表单操作的脚本)中,尝试以下操作:
<?php
$username = $_GET['username'];
$location = $_GET['location'];
$filepath = "/UploadedFiles/$username/$location/files.xml";
?>
或
$filepath = "/UploadedFiles/".$username."/".$location."/files.xml";
好的,假设您有以下值:
用户名
,位置
然后,(如果我答对了你的问题)在响应脚本(接收表单操作的脚本)中,尝试以下操作:
<?php
$username = $_GET['username'];
$location = $_GET['location'];
$filepath = "/UploadedFiles/$username/$location/files.xml";
?>
或
$filepath = "/UploadedFiles/".$username."/".$location."/files.xml";
无论您在表单中使用post或get方法,这都将起作用。只需确保为输入文本html元素选择字段名、用户名和位置
$filepath = "/UploadedFiles/{$_REQUEST['username']}/{$_REQUEST['location']}/files.xml"
无论您在表单中使用post或get方法,这都将起作用。只需确保为输入文本html元素选择字段名、用户名和位置
$filepath = "/UploadedFiles/{$_REQUEST['username']}/{$_REQUEST['location']}/files.xml"
必须将它们定义为变量并包含在字符串中
$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....
}
必须将它们定义为变量并包含在字符串中
$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....
}
如果我没弄错的话,常规的连接就行了。您尝试了什么?您可以编辑此问题以添加更多详细信息。当然不改变话题。嗨@Starx,我只是想让你知道我已经更新了我的帖子。如果我理解正确的话,常规的连接就可以了。您尝试了什么?您可以编辑此问题以添加更多详细信息。当然不改变话题。嗨@Starx,我只是想让你知道我已经更新了我的帖子。谢谢你的好意。不幸的是,我没能做到这一点,但在浏览了我原来的帖子后,我没有提供足够的细节,对此我深表歉意,所以我提出了一个新的帖子。友善的regards@IRHM,哪一个是你的帖子?非常感谢你的回复,我会在几分钟内修改帖子。谢谢你的好意。不幸的是,我没能做到这一点,但在浏览了我原来的帖子后,我没有提供足够的细节,对此我深表歉意,所以我提出了一个新的帖子。友善的regards@IRHM,哪一个是你的帖子?非常感谢你的回复,我会在几分钟内修改帖子。谢谢你的好意。不幸的是,我无法让这项工作。然而,在浏览了我原来的帖子之后,我没有提供足够的细节,对此我深表歉意。我现在已经添加了更多细节。谢谢你的好意。不幸的是,我无法让这项工作。然而,在浏览了我原来的帖子之后,我没有提供足够的细节,对此我深表歉意。我现在已经添加了更多细节。谢谢你的好意。不幸的是,虽然我没有收到任何错误,但我无法让它工作。然而,我认为这是我的脚本和我缺乏PHP知识,而不是你的代码,我也觉得我原来的帖子没有包含足够的细节,对此表示歉意。我现在补充了这一点。谢谢你的好意。不幸的是,虽然我没有收到任何错误,但我无法让它工作。然而,我认为这是我的脚本和我缺乏PHP知识,而不是你的代码,我也觉得我原来的帖子没有包含足够的细节,对此表示歉意。我现在补充了这一点。问候