uploadify不会上传到服务器

时间:2013-01-25 15:47:37

标签: php upload uploadify

它显示没有错误,它看起来像工作。但它不会将图像上传到服务器。

在localhost上使用相同的代码。

阅读有关此问题的内容,但仍然没有解决方案:

同样的问题:

http://www.uploadify.com/forums/discussion/6974/upload-ok-but-file-not-in-target-folder/p1

http://www.uploadify.com/forum/#/discussion/5527/upload-does-not-work-no-errors/p1

Jquery的:

$("#fileUpload2").fileUpload({
    'uploader': 'uploadify/uploader.swf',
    'cancelImg': 'uploadify/cancel.png',
    'script': 'uploadify/upload.php',
    'folder': '/files',
    'multi': true,
    'buttonText': 'start upl',
    'checkScript': 'uploadify/check.php',
    'displayData': 'speed',
    'simUploadLimit': 2,
    'onComplete':function(event, ID, fileObj, response, data){
        foto=foto+fileObj.name;

        }
});

upload.php的

<?php
if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
    $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
    $ff= $_FILES['Filedata']['name'];
    echo $ff;
    // Uncomment the following line if you want to make the directory if it doesn't exist
    // mkdir(str_replace('//','/',$targetPath), 0755, true);

    move_uploaded_file($tempFile,$targetFile);
}

echo '1';

?>

1 个答案:

答案 0 :(得分:0)

你那里有无效的错误处理。检查非空的$ _FILES NOT 是检查上传成功的正确方法。上传失败仍会将数据填充到$ _FILES中。至少,你应该

if ($_FILES['Filedata']['error'] !== UPLOAD_ERR_OK) {
   die("Upload failed with error code " . $_FILES['Filedata']['error'];
}

然后查看您获得的错误代码:http://php.net/manual/en/features.file-upload.errors.php

您还在移动()调用中直接使用用户提供的文件名,允许恶意用户在您的服务器上随意涂写上传的文件 ANYWHERE ,让您完全接受完整的系统接管。在花时间学习基本的PHP(和Web)安全性之前,不要将此代码放到实时网站上。

相关问题