3 Replies - 2774 Views - Last Post: 11 March 2014 - 02:52 PM

#1 ChrisNt  Icon User is offline

  • cute bug

Reputation: 262
  • View blog
  • Posts: 896
  • Joined: 31-July 13

Send file without refresh

Posted 10 March 2014 - 01:39 AM

im using this plugin to send a file to the server without refreshing the page.But it always refresh the page when files are uploaded..What i want to achieve is the user to be able to watch a video while uploading the files,now when the files are uploaded the video reloads...i use html5 video

http://hayageek.com/...upload-file.php


            <div id="multipleupload">Upload</div>
            <div id="eventsmessage">message</div>
    




  $(document).ready(function() {
                $("#multipleupload").uploadFile({
                    url: "upload.php",
                    multiple: true,
                    allowedTypes: "mov",
                    fileName: "myfile",
                  
                    onsubmit: function(files)
                    {
                        $("#eventsmessage").html($("#eventsmessage").html() + 
                          "<br/>Submitting:" + JSON.stringify(files));    
                    },
                    onSuccess: function(files, data, xhr)
                    {
                        $("#eventsmessage").html($("#eventsmessage").html() +
                         "<br/>Success for: " + JSON.stringify(data));  
                    },
                    afterUploadAll: function()
                    {
                        $("#eventsmessage").html($("#eventsmessage").html() + 
                          "<br/>All files are uploaded");
                    },
                    onerror: function(files, status, errMsg)
                    {
                        $("#eventsmessage").html($("#eventsmessage").html() +
                          "<br/>Error for: " + JSON.stringify(files));
                    }  
                }); 
            });




PHP

<?php
include_once("C:/xampp/htdocs/PhpProject1/PHP/connect.php");

session_start();
if (!isset($_SESSION['user_id'])) {
    header("location: ../index.php");
}

 $userId = $_SESSION['user_id'];
    $path = 'id' . $userId;

    // create file with users id
    if (!is_dir($path)) {
        mkdir($path);
    }


$output_dir = $path;
if (isset($_FILES["myfile"])) {
    $ret = array();

    $error = $_FILES["myfile"]["error"];

    //You need to handle  both cases
    //If Any browser does not support serializing of multiple files using FormData() 

    if (!is_array($_FILES["myfile"]["name"])) { //single file

        $fileName = $_FILES["myfile"]["name"];
        move_uploaded_file($_FILES["myfile"]["tmp_name"], "$output_dir/" . $fileName);
        $ret[] = $fileName;

    } else {  //Multiple files, file[]

        $fileCount = count($_FILES["myfile"]["name"]);

        for ($i = 0; $i < $fileCount; $i++) {
            $fileName = $_FILES["myfile"]["name"][$i];
            move_uploaded_file($_FILES["myfile"]["tmp_name"][$i], $output_dir . $fileName);
            $ret[] = $fileName;
        }
    }
    echo json_encode($ret);
}

This post has been edited by ChrisNt: 10 March 2014 - 01:50 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Send file without refresh

#2 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1934
  • View blog
  • Posts: 5,934
  • Joined: 15-January 14

Re: Send file without refresh

Posted 11 March 2014 - 10:49 AM

Use your browser's developer tools to break on all Javascript errors or exceptions, and see what happens. There might be a Javascript error happening during the submit callback that is canceling the callback and letting the submission proceed as normal.
Was This Post Helpful? 0
  • +
  • -

#3 ChrisNt  Icon User is offline

  • cute bug

Reputation: 262
  • View blog
  • Posts: 896
  • Joined: 31-July 13

Re: Send file without refresh

Posted 11 March 2014 - 01:15 PM

When i run my project with netbeans problem appears but when i copy paste the path of my index file in the brownser it works fine..no idea why this happens.

**maybe because netbeans updates my folder when i submit a file? really strange

This post has been edited by ChrisNt: 11 March 2014 - 01:31 PM

Was This Post Helpful? 0
  • +
  • -

#4 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1934
  • View blog
  • Posts: 5,934
  • Joined: 15-January 14

Re: Send file without refresh

Posted 11 March 2014 - 02:52 PM

I have no experience with Netbeans, it is always preferable to do all of your testing in an actual browser environment instead of something like Netbeans. That's one of the problems with IDEs in general. Dreamweaver, for example, used to use Opera's Presto engine for page rendering. That's fine if you're an Opera user like myself, but if you want the page to work in IE or Firefox it doesn't matter if it renders fine in Presto, what matters is if it renders in IE or Firefox. It doesn't matter so much if your site does or does not work in an IDE, test it in the actual browsers. I'm sure that you can set Javascript breakpoints or something similar in Netbeans though, so it shouldn't be that hard to track down that error just to fix it in the IDE preview.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1