2011-11-05 118 views
0

我正在使用uploadify,我的问题是这些文件没有上传。Uploadify脚本没有错误,但没有上传

这是我的代码:

在uploadify.php我给自己定了根路径:/

像这样:

$targetFolder = '/'; // Relative to the root 

那么剩下的脚本:

<script type="text/javascript"> 
jQuery(document).ready(function() { 


    $('#file_upload').uploadify({ 
     'uploader' : '/myIncludes/UploadiftyFolder/uploadify.php', 
     'swf' : '/myIncludes/UploadiftyFolder/uploadify.swf', 
     'cancelImg' : '/myIncludes/UploadiftyFolder/cancel.png', 
     'folder' : '/myUploads/UploadsDirectory/images/', 
     'auto'  : true, 
     'multi'   : false, 
     'checkExisting' : false 
     }); 
}); 
</script> 

//Finally 

<input id="file_upload" type="file" name="Filedata" /> 
<a href="javascript:$('#file_upload').uploadifyUpload();">Upload Files</a> 

当我尝试上传图片时,它一切正常(看起来太),它说 - 完成...

但是没有任何内容正在上传。

任何想法?

UPDATE:

这里是我的服务器结构的路径:

我的路径:

root/myIncludes/UploadiftyFolder/ <--Here are all the uploadify files 

root/myUploads/UploadsDirectory/images/ <--Here is where I need to upload 

这里是uploadify我的当前设置:

folder --> '/myUploads/UploadsDirectory/images/', 

and in uploadify.php --> $targetFolder = '/'; // Relative to the root 

这里是休息uploadify.php文件的文件...我没有改变任何东西:

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

回答

1

先给 “〜/” 文件夹上传

(OR)之前这里是整个脚本:

<script type="text/javascript"> 
    $(window).load(
function() { 
    $("#fileInput1").uploadify({ 
     'uploader': 'scripts/uploadify.swf', 
     'cancelImg': 'images/cancel.png', 
     'buttonText': 'Browse Files', 
     'script': 'UploadVB.ashx', 
     'folder': 'uploads', 
     'fileDesc': 'Image Files', 
     'fileExt': '*.jpg;*.jpeg;*.gif;*.png', 
     'queueSizeLimit': 9999, 
     'simUploadLimit': 2, 
     'sizeLimit': 4000000, 
     'multi': true, 
     'auto': true, 
     'onComplete': function (event, queueID, fileObj, response, data) { 
         $("#thumbnail").append(response) 

     }, 

     'onError': function (event, ID, fileObj, errorObj) { 
      alert(errorObj.type + ' Error: ' + errorObj.info); 
     } 


    }); 
} 
); 
</script> 
+0

我正在使用php上传器而不是..'uploader':'/files/uploadify.php'...但是我添加了oncomplete和onerror,但没有得到任何回报。 – Satch3000

+0

这只是问题与所需的上传文件夹确保参考路径是正确的上传文件夹在您的uploadify.php – coder

4

对我来说,问题是在uploadify.php文件。他们正在使用:

$tempFile = $_FILES['Filedata']['tmp_name']; 
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; 
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name']; 

$targetFolder由您在顶部定义。

再后来:

move_uploaded_file($tempFile,$targetFile); 

默认例子追加的目标文件夹到的$_SERVER['DOCUMENT_ROOT']结束。我的$_SERVER['DOCUMENT_ROOT']实际上是C:\xampp\htdocs。因此,为了使你的工作目标文件夹必须是:

$targetFolder = "/yourSiteFolder/wherever/your/upload/folder/is";

我做了什么:

摆脱$_SERVER['DOCUMENT_ROOT']干脆。这里是我的uploadify.php文件:

<?php 
/* 
Uploadify v3.1.0 
Copyright (c) 2012 Reactive Apps, Ronnie Garcia 
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/ 

// Define a destination 
//$targetFolder = '/sandbox/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($_FILES["Filedata"]["tmp_name"], "uploads/" . $_FILES["Filedata"]["name"]); 
     echo '1'; 
    } else { 
     echo 'Invalid file type.'; 
    } 
} 
?> 

主要的变化是,我已经更换了这一点:

move_uploaded_file($tempFile,$targetFile); 

与此:

move_uploaded_file($_FILES["Filedata"]["tmp_name"], "uploads/" . $_FILES["Filedata"]["name"]); 

然后注释掉几行文字间没有”不再需要了。

这是我check-exists.php文件:

<?php 
/* 
Uploadify v3.1.0 
Copyright (c) 2012 Reactive Apps, Ronnie Garcia 
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/ 

// Define a destination 
//$targetFolder = 'uploads'; // Relative to the root and should match the upload folder  in the uploader script 

if (file_exists("uploads/" . $_POST['filename'])) { 
    echo 1; 
} else { 
    echo 0; 
} 
?> 

这是我的jQuery代码:

$(function() { 
    $("#uploadify").uploadify({ 
     height  : 30, 
     swf   : 'uploadify/uploadify.swf', 
     uploader  : 'uploadify/uploadify.php', 
     width   : 120 
    }); 
}); 

有关我的网站的文件结构的说明:

所有uploadify文件在我的网站的根目录中名为uploadify的文件夹中。在uploadify之内有一个名为uploads的文件夹,这是上传文件的位置。

希望有所帮助。

+0

嘿,这对我很有用。 –

1

对我来说,我所要做的就是摆脱$ targetPath定义中的$ _SERVER ['DOCUMENT_ROOT']。然后我还使用“上传”而不是“/ uploads”作为我的$ targetFolder。

2

我在这里尝试了所有其他的建议,但没有一个为我工作。然后我意识到Uploadify的3.2版(以及以前的版本)需要时间戳和哈希标记才能完成上传。

首先,我必须将脚本从外部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文件才能找到它。

相关问题