对ajax图片上传真的很困惑

发布于 2024-12-06 13:21:30 字数 3079 浏览 2 评论 0原文

在过去的几周里,我就这个主题提出了几个问题。似乎我越努力去解决这个问题,离解决方案就越远。这可能只是因为我是个白痴,

下面是我迄今为止所学到的内容的简要总结:

A) 确实没有 AJAX 上传功能。您实际上只是更新 Ipage 表单元素。它看起来像 AJAX,但实际上不是。

B) valuens 没有 AjaxUpload 插件。至少没有这么命名。在查看了几个关于 ajax 上传的教程之后,每个教程都引用了 AjaxUpload.js 插件,并且完全是 bubkis,因为在他的页面上,它没有命名为 AjaxUpload.js,而是命名为其他名称。如果它真的存在的话。我不想经历重命名的麻烦,只是害怕看到会发生什么,因为这通常只会导致丑陋的错误狂欢。

C) 很多解决方案似乎都使​​用 CAKE。不太确定那到底是什么,但它看起来像是某种基于流行的 MVC 设计模式的 PHP 设计模式。但不太确定。

D)这似乎是一项非常艰巨的任务。这不需要几行代码和祈祷。
D1) PHP 代码看起来很简单。只需调用移动文件的函数... D2) jquery 看起来有点棘手。这是您调用上述 php 函数的地方。当我单击文本框内的上传时,我想调用它...一个简单的

    $('form#inputId').change(function (){//insert the code to call php function here});

应该可以做到这一点,对吗?诀窍是我在这些大括号内写什么?

这将是我对这个主题的理解的总和...这就是我所拥有的...

    <?php
    $link = mysql_connect('greetmeet.ipagemysql.com', 'greetmeet', 'Maverick$41'); 
    mysql_select_db(first_1) or die("Opps, You are pretty Got-Damned Stupid!  Did you     realize that?!?!?");
    $target = './Uploads/'; 
    $target = $target . basename( $_FILES['uploaded']['name']) ; 
    $ok=1; 

    $path = "uploads/";
    $Email = $_SESSION['user_email']; //This should be a session ID.  Must talk this over with Fellow Coder That Nigga, LJeezy West...
    $valid_formats = array("jpg", "png", "gif", "bmp","jpeg");

    if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
    {
        $name = $_FILES['photoimg']['name'];
        $size = $_FILES['photoimg']['size'];
        if(strlen($name))
        {
            list($txt, $ext) = explode(".", $name);
            if(in_array($ext,$valid_formats))
            {  
                if($size<(1024*1024)) // Image size max 1 MB
                {
                    $actual_image_name = time().$session_id.".".$ext;
                    $tmp = $_FILES['photoimg']['tmp_name'];
                    if(move_uploaded_file($tmp, $path.$actual_image_name))
                    {
                        mysql_query("UPDATE user_pics SET    profile_pic='$actual_image_name' WHERE Email='$Email'");
                        echo "<img src='uploads/".$actual_image_name."'         class='preview'>";
                    }
                    else
                        echo "failed";
                }
                else
                    echo "Image file size max 1 MB";
                }
            else
                echo "Invalid file format..";
            }
        else
            echo "Please select image..!";
        exit;
    }
    ?>

这将是我想要调用的 php 函数,该函数会将文件移动到我的服务器,然后将链接放入数据库。

我再说一遍,我的 jquery 代码非常混乱,而且可能都是错误的。我只是不知道在那里做什么。我现在只想要一些非常简单的东西。没什么特别的,只需上传带有预览的照片,然后提交即可完成一切。无论如何,我可以通过将图片直接放入 mysql 来做到这一点吗?

还, 这个教程看起来很有用... http://www.akchauhan.com/upload-image-using-hidden- iframe/ 但真的很难理解...

这是一个使用 AjaxUpload 的插件示例... AjaxUpload.js 文件在哪里? http://www.zurb.com/playground/ajax_upload

Over the last couple of weeks I have asked a couple of questions on this subject. It seems as though the harder I try to figure this out, the further away from a solution I appear to be. That may just be a function of me being an idiot

Here is a brief summary of what I have learned so far:

A) There is really no AJAX upload functionality. You are really just updating an Ipage form element. It appears like AJAX, but it truly isn't.

B) There is no AjaxUpload plugin by valumns. At least not named that. After looking at several tutorials on ajax upload that each refer to the AjaxUpload.js plugin and getting absolutely bubkis because on his page, it is not named AjaxUpload.js, it is name something else. If it is even there at all. I didn't feel like going through the hassle of renaming it, and just freaking seeing what happens, because that usually just results in an ugly orgy of errors on obsenities.

C) Alot of the solutions appear to use CAKE. Not really sure what the hell that is, but it looks like some kind of PHP design pattern based off of the popular MVC design pattern. Not really sure though.

D) this appears to be a really hard task. Not something that would take a couple of lines of code and prayer.
D1) The PHP code seems simple enough. Just call the function that moves files...
D2) The jquery seems a little bit trickier. Here is where you are calling the above php function. I want to call this when I click inside the text box for the upload... A simple

    $('form#inputId').change(function (){//insert the code to call php function here});

should do that right? The trick is what I write inside of those curly brackets?

That would be the sum-total of what I understand about the subject... This is what I have...

    <?php
    $link = mysql_connect('greetmeet.ipagemysql.com', 'greetmeet', 'Maverick$41'); 
    mysql_select_db(first_1) or die("Opps, You are pretty Got-Damned Stupid!  Did you     realize that?!?!?");
    $target = './Uploads/'; 
    $target = $target . basename( $_FILES['uploaded']['name']) ; 
    $ok=1; 

    $path = "uploads/";
    $Email = $_SESSION['user_email']; //This should be a session ID.  Must talk this over with Fellow Coder That Nigga, LJeezy West...
    $valid_formats = array("jpg", "png", "gif", "bmp","jpeg");

    if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
    {
        $name = $_FILES['photoimg']['name'];
        $size = $_FILES['photoimg']['size'];
        if(strlen($name))
        {
            list($txt, $ext) = explode(".", $name);
            if(in_array($ext,$valid_formats))
            {  
                if($size<(1024*1024)) // Image size max 1 MB
                {
                    $actual_image_name = time().$session_id.".".$ext;
                    $tmp = $_FILES['photoimg']['tmp_name'];
                    if(move_uploaded_file($tmp, $path.$actual_image_name))
                    {
                        mysql_query("UPDATE user_pics SET    profile_pic='$actual_image_name' WHERE Email='$Email'");
                        echo "<img src='uploads/".$actual_image_name."'         class='preview'>";
                    }
                    else
                        echo "failed";
                }
                else
                    echo "Image file size max 1 MB";
                }
            else
                echo "Invalid file format..";
            }
        else
            echo "Please select image..!";
        exit;
    }
    ?>

That would be the php function that I want to call that would move the file to my server and then put the link in the database.

my Again, my jquery code is pretty confusing, and probably all wrong. I just doin't know what to do there. I just want something really simple for now. Nothing fancy, Just upload the photo with preview and then on submit finalize everything. Is there anyway that I could do this by putting the picture directly in mysql btw?

Also,
This tutorial seemed usefull...
http://www.akchauhan.com/upload-image-using-hidden-iframe/
But really hard to understand...

And this is an example of a pluggin that uses AjaxUpload... Where is the AjaxUpload.js file?
http://www.zurb.com/playground/ajax_upload

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

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

发布评论

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

评论(2

二智少女猫性小仙女 2024-12-13 13:21:30

我建议使用插件“ajaxfileupload.js”。
这非常容易使用。
请检查下面的链接以获取其说明并下载:
http://www.phpletter.com/Our-Projects/AjaxFileUpload/

注意:这没有使用任何闪光灯。这是它好的一面。

I suggest using the plugin "ajaxfileupload.js".
This is quite easy to use.
Please check the link below for its instructions and download:
http://www.phpletter.com/Our-Projects/AjaxFileUpload/

Note: This is not using any flash. That is the good aspect of it.

最美的太阳 2024-12-13 13:21:30

教程 中,您提到您可能会迷失在链接中,因为所使用的组件不再是维护。无论如何,您可以在此处找到该项目。您想要的是根文件夹中的文件 ajaxupload.js项目的。

In the tutorial you mentioned you may get lost in the links because the component that is used stopped to be maintaned. Anyway, you find the project here. What you want is the file ajaxupload.js in the root folder of the project.

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