我正在使用uploadify,虽然它可以正常工作但不会上传到文件夹中。我怎样才能复制?该文件夹是777。
如果需要,这是页面:
http://www.dilyurdu.com/uploadify/
// script
$(function() {
$("#file_upload_1").uploadify({
height : 30,
swf : 'uploadify.swf',
uploader : 'uploadify.php',
width : 120
});
});
// php
$targetFolder = '/uploads'; // Relative to the root
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($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 :(得分:2)
试试这个
<script type="text/javascript">
$(document).ready(function() {
$(function() {
$("#file_upload").uploadify({
'uploader' : '<?php echo base_url();?>flash/uploadify.swf',
'script' : '<?php echo base_url();?>scripts/uploadify.php',
'folder' : '/folder_name_where_you_want_to_upload/',
'height' : 30,
'onError' : function(event,queueID,fileObj,errorObj){
// alert(errorObj["type"]+" - "+errorObj["status"]+" - "+errorObj["text"]);
},
});
});
});
</script>
还要在uploadify.php中回显$ targetPath,以便跟踪上传路径。
答案 1 :(得分:0)
我在这里尝试了所有其他建议,但它们都没有为我工作。然后我意识到版本3.2的Uploadify(也可能是以前的版本)需要时间戳和散列令牌才能完成上传。
首先,我必须将脚本从外部JS文件移动到我的PHP文件,以便我可以从PHP获取时间戳。 (您也可以通过隐藏的输入值或其他方法执行此操作,但这是最简单的方法。)然后我必须将'formData' option添加到我的Uploadify调用以及一些获取时间戳并对其进行哈希处理的PHP代码使用唯一的盐(您应该将其更改为随机字符串):
<?php $timestamp = time();?>
<script>
$('#file_upload').uploadify({
'swf' : '/uploadify/uploadify.swf',
'uploader' : '/uploadify/uploadify.php',
'formData' : {
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5("unique_salt" . $timestamp);?>'
}
});
</script>
虽然版本3.2中似乎需要此代码,但implementation documentation中未提及此代码。我不得不查看下载包中的index.php文件来查找它。
答案 2 :(得分:0)
我遇到了同样的问题。在尝试了这篇文章中提到的所有内容以及关于这个主题的其他帖子之后,我意识到我必须设置目标文件夹的绝对路径。 所以,对我有用的是改变uploadify.php中的以下内容:
$ targetFolder ='/ var / www / vhosts / DOMAIN / httpdocs / uploads'
然后我删除了DOCUMENT_ROOT FROM $ targetPath,只剩下$ targetFolder,如下所示: $ targetPath = $ targetFolder;
我还在我的JS调用中添加了时间戳和令牌,如上所述。
现在一切正常。希望这有助于某人: - )
答案 3 :(得分:0)
问题在于上传文件夹的路径 我的道路:
$ targetFolder ='../../upload/orginal'; //相对于根