gpt4 book ai didi

PHP jQuery : Where to specify uploadify destination folder

转载 作者:行者123 更新时间:2023-12-01 03:19:32 25 4
gpt4 key购买 nike

我有一个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.';
}
}

最佳答案

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.';
}
}

关于PHP jQuery : Where to specify uploadify destination folder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11406069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com