Uploadify-操作完成,但不进行上传

时间:2012-07-20 19:07:22

标签: php jquery file-upload uploadify

我将Uploadify下载到我的网站,但无法上传所选文件。 你可以在这里看到它:http://www.guydavid.org/test/

文件夹树:

  • 测试
    • uploadify
      • ... uploadify files ...
    • 上传
    • 的index.php

的index.php:

<!DOCTYPE html>
<html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<title>File Management</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="uploadify/jquery.uploadify-3.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="uploadify/uploadify.css" />
<script type="text/javascript">
$(document).ready(function() {
    $(function() {
        $('#file_upload').uploadify({
            'swf'      : 'uploadify/uploadify.swf',
            'uploader' : 'uploadify/uploadify.php',
            'method'   : 'post',
            'formData' : { 'someKey' : 'someValue' },
            'folder'      : '/uploads',
            'auto'        : true,
            'onError'     : function (event,ID,fileObj,errorObj) {
                alert(errorObj.type + ' Error: ' + errorObj.info);
            }
        });
    });
});
</script>
</head>
<body>

<input type="file" name="file_upload" id="file_upload" />

</body>

</html>

uploadify.php:

<?php
/*
Uploadify
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

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

可能是什么原因造成的?我为所有文件设置了777个烫发。

没有显示错误。

1 个答案:

答案 0 :(得分:3)

我注意到了

前面的../
$targetFolder = '../uploads';

在顶部的INDEX.PHP文件中尝试此操作,看看你在那里做了什么..我的猜测是错误的路径......

<?php
$targetFolder = '../uploads';
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
echo $targetPath;
?>

应该是

<?php
$targetFolder = '/uploads';
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
echo $targetPath;
?>

<?php
$targetFolder = 'uploads';
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
echo $targetPath;
?>

取决于您的服务器设置和尾部斜杠......