我正在运行uploadify脚本,基本设置。当我将图像的目标文件夹硬编码到uploadify.php
时工作正常 - 现在我想使该文件夹动态化。我该怎么做?
我有一个PHP变量$uploadify_path
,其中包含我想要的文件夹的路径。我已经在uploadify.php和check_exists.php中为$targetPath = path/to/directory
切换了我的硬编码$targetPath = $uploadify_path
,但它不起作用。文件上传动画运行,表示已完成,但目录仍为空。该文件也没有隐藏在其他地方。
我看到Javascript中有一个选项来指定文件夹。我也试过这个,但无济于事。
如果有人可以教我如何将此变量目的地传递给uploadify,我将非常感激。
我包含了我当前的检查代码(基本上是默认的):
Javascript
<script type="text/javascript">
$(function() {
$('#file_upload').uploadify({
'swf' : 'uploadify/uploadify.swf',
'uploader' : 'uploadify/uploadify.php',
// Put your options here
});
});
</script>
uploadify.php
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $uploadify_path; // Relative to the root
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetFile = $targetPath . $_FILES['Filedata']['name'];
// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo '1';
} else {
echo 'Invalid file type.';
}
}
答案 0 :(得分:4)
<强> JS 强>
<script type="text/javascript">
$(function() {
$('#file_upload').uploadify({
'formData' : {'path':'/file/path'},
'swf' : 'uploadify/uploadify.swf',
'uploader' : 'uploadify/uploadify.php'
// Put your options here
});
});
</script>
<强> PHP 强>
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_POST['path']; // Relative to the root
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetFile = $targetPath . $_FILES['Filedata']['name'];
// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo '1';
} else {
echo 'Invalid file type.';
}
}