how can i return newly updated file name to CuteWebUI_AjaxUploader_OnTaskComplete(task)?

Last post 02-16-2012, 12:20 AM by manpakhong. 6 replies.
Sort Posts: Previous Next
  •  02-12-2012, 2:51 AM 72989

    how can i return newly updated file name to CuteWebUI_AjaxUploader_OnTaskComplete(task)?

    front end code:
        <?php
            $uploader=new PhpUploader();

            $uploader->MultipleFilesUpload=true;
            $uploader->InsertText="Select multiple files (Max 10M)";
            
            $uploader->MaxSizeKB=10240;
            $uploader->AllowedFileExtensions="*.jpg,*.png,*.gif,*.bmp";
            $uploader->SaveDirectory="../pics/";
            $uploader->UploadUrl="../php/cmds/PhpFileUploadCmd.php";
            $uploader->FlashUploadMode="Partial";
            $uploader->Render();
        ?>

    <script type='text/javascript'>
        function CuteWebUI_AjaxUploader_OnTaskComplete(task)
        {
            var div=document.createElement("div");
            var table=document.createElement("table");


            var tableRow=document.createElement("tr");
            var tableData=document.createElement("td");
            var tableData1=document.createElement("td");

            var input=document.createElement("input");
            input.setAttribute("type","text");
            input.setAttribute("name", "albumPicComment");

            var link=document.createElement("a");
            link.setAttribute("href","../pics/"+task.FileName);
            link.innerHTML="You have uploaded file : ../pics/"+task.FileName;
            link.target="_blank";
            
            var img=document.createElement("img");
            img.setAttribute("src", "../pics/" + task.FileName);
            img.setAttribute("class", "postBackPics");

            div.appendChild(table);
            table.appendChild(tableRow);
            tableRow.appendChild(tableData);
            tableRow.appendChild(tableData1);
            tableData.appendChild(img);
            tableData1.appendChild(input);
            img.appendChild(link);
            document.body.appendChild(div);
        }
        </script>
     
    background code :
     
    <?php

        $currentDir = getcwd();
        $rootDir = 'albums';
        $findRootDirPos = strpos($currentDir, $rootDir, 0);
        $currentDir =  substr_replace($currentDir, '' , $findRootDirPos + strlen($rootDir));
        $currentDir = $currentDir . '/';
        
        require_once $currentDir . "php/phpFileUploader/phpuploader/include_phpuploader.php";
        
        $uploader=new PhpUploader();
        
        $mvcfile=$uploader->GetValidatingFile();
        
        if($mvcfile->FileName=="accord.bmp")
        {
            $uploader->WriteValidationError("My custom error : Invalid file name. ");
            exit(200);
        }
        
        //USER CODE:
        
        $targetfilepath= $currentDir . "pics/pre" . $mvcfile->FileName;
        if( is_file ($targetfilepath) )
            unlink($targetfilepath);
        $mvcfile->MoveTo( $targetfilepath );
        
        $uploader->WriteValidationOK();

    ?>
     
    ================================
    regards,
     
    Man Pak Hong, Dave
     
    Analyst Programmer
     

    Man Pak Hong, Dave
  •  02-12-2012, 9:17 AM 72991 in reply to 72989

    Re: how can i return newly updated file name to CuteWebUI_AjaxUploader_OnTaskComplete(task)?

    Can I do any modification to make the $uploader->WriteValidationOK() to return my parameters to front-end:
     function CuteWebUI_AjaxUploader_OnTaskComplete(task), the task? e.g. task.MyNewFileName, task.DatabaseSid?
     
     
    Thanks for all experts,
     
    Regards,
    Man Pak Hong, Dave
     
     

    Man Pak Hong, Dave
  •  02-12-2012, 10:35 PM 72996 in reply to 72989

    Re: how can i return newly updated file name to CuteWebUI_AjaxUploader_OnTaskComplete(task)?

    Hi,
     
    Here is the steps:
     
    1 . SERVER : open the include_phpuploader.php , find the function WriteValidationOK() , and change it to :
     
     
    2 . SERVER : in the handler.php , write this code for test :
     
    $uploader->WriteValidationOK('here is the server message');
     
    3 . JS :  in the CuteWebUI_AjaxUploader_OnTaskComplete(task) , use
     
    task.ServerData to get the server message.
     
     
    Regards,
    Terry
     
  •  02-13-2012, 2:35 AM 73001 in reply to 72996

    Re: how can i return newly updated file name to CuteWebUI_AjaxUploader_OnTaskComplete(task)?

    Thanks Expert Terry, You help me a lot, Let me test it. Thanks Thanks.
     
    Regards,
     
    Man Pak Hong, Dave 
     

    Man Pak Hong, Dave
  •  02-13-2012, 3:07 AM 73003 in reply to 73001

    Re: how can i return newly updated file name to CuteWebUI_AjaxUploader_OnTaskComplete(task)?

    Yeah~~~~ I have tested it , it works. Thanks Terry.
     
    May I ask one more greedy question?
     
    Can I pass a object back to front end?
     
    Regards,
     
    Man Pak Hong, Dave
     

    Man Pak Hong, Dave
  •  02-15-2012, 9:14 AM 73030 in reply to 73003

    Re: how can i return newly updated file name to CuteWebUI_AjaxUploader_OnTaskComplete(task)?

    Hi,
     
    You can't send object to client directly.
     
    If you want to send more informations , you can join them like this
     
    $msg="$data1|$data2|$name1|$name2"
     
    and split each parts when you get task.ServerData like this:
     
    var parts=task.ServerData.split('|');
    var data1=parts[0];
    var data2=parts[1];
    var name1=parts[2];
    var name2=parts[3];
     
    Regards,
    Terry
     
  •  02-16-2012, 12:20 AM 73036 in reply to 73030

    Re: how can i return newly updated file name to CuteWebUI_AjaxUploader_OnTaskComplete(task)?

    Thanks Thanks, Terry.
     
    Regards,
     
    Man Pak Hong, Dave
    manpakhong

    Man Pak Hong, Dave
View as RSS news feed in XML