Uploadify- operations completes, but no upload is made

我的梦境 提交于 2020-01-05 07:16:10

问题


I downloaded Uploadify to my site, but it fails to upload selected files. You can see it live here: http://www.guydavid.org/test/

Folder tree:

  • test
    • uploadify
      • ...uploadify files...
    • uploads
    • 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.';
    }
}
?>

What can be the cause of it? I set 777 perms to all files.

It shows no error.


回答1:


I noticed the ../ in front of your

$targetFolder = '../uploads';

Try this in your INDEX.PHP file at the top to see what you are actually doing there .. My guess is it's the wrong path ...

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

Should be probably

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

or

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

depending on your server settings and trailing slash ...



来源:https://stackoverflow.com/questions/11585527/uploadify-operations-completes-but-no-upload-is-made

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!