1

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

文件夹树:

  • 测试
    • 上传
      • ...上传文件...
    • 上传
    • 索引.php

索引.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>

上传.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 权限。

它显示没有错误。

4

1 回答 1

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;
?>

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

于 2012-07-20T19:31:44.440 回答