本文介绍了Uploadify操作完成,但是没有上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



文件夹树:


  • 测试

    • uploadify

      • ... uploadify文件...


      • 上传

      • index.php




    index.php:

     <!DOCTYPE html> 
    < meta content ='text / html; charset = utf-8'http-equiv ='Content-Type'>
    < title>档案管理< / title>
    < script type =text / javascriptsrc =http://code.jquery.com/jquery-1.7.2.min.js>< / script>
    < script type =text / javascriptsrc =uploadify / jquery.uploadify-3.1.min.js>< / script>
    < link rel =stylesheettype =text / csshref =uploadify / uploadify.css/>
    < script type =text / javascript>
    $(document).ready(function(){
    $(function(){
    $('#file_upload')。uploadify({$ b $'swf':'uploadify /uploadify.swf',
    'uploader':'uploadify / uploadify.php',
    'method':'post',
    'formData':{'someKey':'someValue' },
    'folder':'/ uploads',
    'auto':true,$ b $'onError':function(event,ID,fileObj,errorObj){
    alert errorObj.type +'错误:'+ errorObj.info);
    }
    });
    });
    });
    < / script>
    < / head>
    < body>

    < input type =filename =file_uploadid =file_upload/>

    < / body>

    < / html>

    uploadify.php:

     <?php 
    / *
    Uploadify
    版权所有(c)2012 Reactive Apps,Ronnie Garcia
    根据MIT License< http: /www.opensource.org/licenses/mit-license.php>
    * /

    //定义目标
    $ targetFolder ='../uploads'; //相对于根

    if(!empty($ _ FILES)){
    $ tempFile = $ _FILES ['Filedata'] ['tmp_name'];
    $ targetPath = $ _SERVER ['DOCUMENT_ROOT']。 $ targetFolder;
    $ targetFile = rtrim($ targetPath,'/')。 '/'。 $ _FILES [ Filedata上] [名];

    //验证文件类型
    $ fileTypes = array('jpg','jpeg','gif','png'); //文件扩展名
    $ fileParts = pathinfo($ _ FILES ['Filedata'] ['name']);
    $ b $ if(in_array($ fileParts ['extension'],$ fileTypes)){
    move_uploaded_file($ tempFile,$ targetFile);
    echo'1';
    } else {
    echo'无效的文件类型';
    }
    }
    ?>

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



    显示没有错误。

    解决方案
      $ 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;
    ?>

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

    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.

    解决方案

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

    这篇关于Uploadify操作完成,但是没有上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 21:24