ajax 上传器的问题

发布于 2025-01-07 08:36:14 字数 2258 浏览 0 评论 0原文

我正在基于此网站的 php 中使用 flash/ajax 文件上传 - http://blog.codeville.net/2008/11/24/jquery-ajax-uploader-plugin-with-progress-bar/

有一点我的行为不一致。

结果之一是进程看起来像是 100% 挂起。 (我可以取消并在页面上执行其他操作,但我只是不进一步。)

另一个是我点击了 upload_success_handler 但文件仍然没有上传到服务器。我什至暂时将权限更改为 777 以排除所有这些问题,但它仍然无法上传。

如果有人对此类事情有任何经验,我想问什么被发送到ajax调用的文件以及如何发送(获取/发布)。另外,我到底需要对ajax调用的文件做什么以及我必须返回什么?我是否只是通过回显文件名来“返回”文件名,或者我实际上会使用“return”命令,就好像它是一个函数一样。博客上的所有内容如下:

处理程序应将上传的文件保存到磁盘,然后返回一个唯一的令牌,例如 GUID 或文件名,以识别您刚刚上传的文件。

目前我在该文件中的代码是这样的

<?php
ini_set('post_max_size', 510000000);
ini_set('upload_max_filesize', 500000000);
ini_set('max_input_time', 20);
ini_set('memory_limit', 520000000);

if (!empty($_FILES['file']['name'])) //checking if file upload box contains a value
{

    $saveDirectory = 'videos/';         //name of folder to upload to
    $tempName = $_FILES['file']['tmp_name'];    //getting the temp name on server
    $fileName1 = $_FILES['file']['name'];       //getting file name on users computer

    $test = array();
    $test = explode(".", $fileName1);
    if((count($test) > 2) || ($test[1] != "avi" && $test[1] != "AVI" && $test[1] != "flv" && $test[1] != "FLV" && $test[1] != "mov" && $test[1] != "MOV" && $test[1] != "mpeg" && $test[1] != "MPEG" && $test[1] != "mp4" && $test[1] != "MP4" && $test[1] != "wmv" && $test[1] != "WMV")){
        $err .= "Invalid file type.  Files must have only one period \".\" and be of type .avi .flv .mov .mpeg .mp4 or .wmv";
        echo $err;

    }else{

        $count = 1;
        do{
        $link = $saveDirectory . $count . $fileName1;
        $count++; 
        }while(is_file($link));
        if (move_uploaded_file($tempName, $link))   //Moves the temp file on server
        {                                           //to directory with real name


            echo $link;

        } 
        else 
        {
            $err .= "There was an error while uploading the file.";

            echo $err;
        }
    }
}
?>

I'm using a flash/ajax file upload in php based on this site - http://blog.codeville.net/2008/11/24/jquery-ajax-uploader-plugin-with-progress-bar/

There is a little inconsistency in the behavior I'm getting.

One result is having the process hang at what looks like 100%. (I can cancel and do other things on the page but I just doesn't go further.)

The other is I hit the upload_success_handler but the file is still not uploaded to the server. I even temporarily changed my permissions to 777 to rule all that out, it still doesn't get uploaded.

If anyone has any experience with this type of thing, I would like to ask what gets sent to the ajax called file and how does it get sent (get/post). Also, what exactly do I need to do on the file called by ajax and what do I have to return? Do I "return" the file name just by echoing it, or would I actually use the "return" command as if it was a function. All it says on the blog Is following is

The handler should save the uploaded file to disk, then return a unique token, such as a GUID or filename, to will identify the file you just uploaded.

Currently what I have for my code in that file is as so

<?php
ini_set('post_max_size', 510000000);
ini_set('upload_max_filesize', 500000000);
ini_set('max_input_time', 20);
ini_set('memory_limit', 520000000);

if (!empty($_FILES['file']['name'])) //checking if file upload box contains a value
{

    $saveDirectory = 'videos/';         //name of folder to upload to
    $tempName = $_FILES['file']['tmp_name'];    //getting the temp name on server
    $fileName1 = $_FILES['file']['name'];       //getting file name on users computer

    $test = array();
    $test = explode(".", $fileName1);
    if((count($test) > 2) || ($test[1] != "avi" && $test[1] != "AVI" && $test[1] != "flv" && $test[1] != "FLV" && $test[1] != "mov" && $test[1] != "MOV" && $test[1] != "mpeg" && $test[1] != "MPEG" && $test[1] != "mp4" && $test[1] != "MP4" && $test[1] != "wmv" && $test[1] != "WMV")){
        $err .= "Invalid file type.  Files must have only one period \".\" and be of type .avi .flv .mov .mpeg .mp4 or .wmv";
        echo $err;

    }else{

        $count = 1;
        do{
        $link = $saveDirectory . $count . $fileName1;
        $count++; 
        }while(is_file($link));
        if (move_uploaded_file($tempName, $link))   //Moves the temp file on server
        {                                           //to directory with real name


            echo $link;

        } 
        else 
        {
            $err .= "There was an error while uploading the file.";

            echo $err;
        }
    }
}
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烙印 2025-01-14 08:36:14

我想通了。结果博客中的 javascript 将文件输入重命名为我给它的其他名称。一旦我相应地调整了我的代码,它就起作用了。在建议我输出 $_FILES[] 变量之后我发现了这一点。我的 asyncupload.php 脚本的输出被移植回 JavaScript 生成的隐藏输入之一。

我只是想我会为其他有此问题的人发布我的解决方案。

I Figured it out. Turns out the javascript from the blog was renaming the file input to something other then what I gave it. Once I adjusted my code accordingly, it worked. I figured that out after It was suggested to me to output the $_FILES[] variables. The output of my asyncupload.php script was ported back into one of the hidden inputs generated by the javascript.

I just figured I would post my solution for anyone else with this issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文