Refresh after uploading is done

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Apr 2008
Posts: 9
Reputation: trevata is an unknown quantity at this point 
Solved Threads: 0
trevata trevata is offline Offline
Newbie Poster

Refresh after uploading is done

 
0
  #1
May 4th, 2009
Hi. In short, how can I make this javascript to refresh the page when uploading is done ?
  1. function $m(theVar){
  2. return document.getElementById(theVar)
  3. }
  4. function remove(theVar){
  5. var theParent = theVar.parentNode;
  6. theParent.removeChild(theVar);
  7. }
  8. function addEvent(obj, evType, fn){
  9. if(obj.addEventListener)
  10. obj.addEventListener(evType, fn, true)
  11. if(obj.attachEvent)
  12. obj.attachEvent("on"+evType, fn)
  13. }
  14. function removeEvent(obj, type, fn){
  15. if(obj.detachEvent){
  16. obj.detachEvent('on'+type, fn);
  17. }else{
  18. obj.removeEventListener(type, fn, false);
  19. }
  20. }
  21. function isWebKit(){
  22. return RegExp(" AppleWebKit/").test(navigator.userAgent);
  23. }
  24. function ajaxUpload(form,url_action,id_element,html_show_loading,html_error_http){
  25. var detectWebKit = isWebKit();
  26. form = typeof(form)=="string"?$m(form):form;
  27. var erro="";
  28. if(form==null || typeof(form)=="undefined"){
  29. erro += "The form of 1st parameter does not exists.\n";
  30. }else if(form.nodeName.toLowerCase()!="form"){
  31. erro += "The form of 1st parameter its not a form.\n";
  32. }
  33.  
  34. if(erro.length>0){
  35. alert("Error in call ajaxUpload:\n" + erro);
  36. return;
  37. }
  38. var iframe = document.createElement("iframe");
  39. iframe.setAttribute("id","ajax-temp");
  40. iframe.setAttribute("name","ajax-temp");
  41. iframe.setAttribute("width","0");
  42. iframe.setAttribute("height","0");
  43. iframe.setAttribute("border","0");
  44. iframe.setAttribute("style","width: 0; height: 0; border: none;");
  45. form.parentNode.appendChild(iframe);
  46. window.frames['ajax-temp'].name="ajax-temp";
  47. var doUpload = function(){
  48. removeEvent($m('ajax-temp'),"load", doUpload);
  49. var cross = "javascript: ";
  50. cross += "window.parent.$m('"+id_element+"').innerHTML = document.body.innerHTML; void(0);";
  51. $m(id_element).innerHTML = html_error_http;
  52. $m('ajax-temp').src = cross;
  53. if(detectWebKit){
  54. remove($m('ajax-temp'));
  55. }else{
  56. setTimeout(function(){ remove($m('ajax-temp'))}, 250);
  57. }
  58. }
  59. addEvent($m('ajax-temp'),"load", doUpload);
  60. form.setAttribute("target","ajax-temp");
  61. form.setAttribute("action",url_action);
  62. form.setAttribute("method","post");
  63. form.setAttribute("enctype","multipart/form-data");
  64. form.setAttribute("encoding","multipart/form-data");
  65. if(html_show_loading.length > 0){
  66. $m(id_element).innerHTML = html_show_loading;
  67. }
  68. form.submit();
  69. }
If you need the php file:
  1. <?php
  2. include "config.php";
  3. @header("Content-Type: text/html; charset=windows-1251");
  4. $fileN = $_REQUEST['pic'];
  5. if (isset($fileN)){
  6. $allowed_ext = "jpg,jpeg,gif,png";
  7. $filesize = $_FILES['pic']['size'];
  8. $maxlimit = 9999999999;
  9. if($filesize > 0){
  10. $filename = strtolower($_FILES['pic']['name']);
  11. $filename = preg_replace('/\s/', '_', $filename);
  12. if($filesize < 1){
  13. $errorList[] = "Empty file!";
  14. echo "Empty file!";
  15. }
  16. if($filesize > $maxlimit){
  17. $errorList[] = "File too big!";
  18. echo "File too big! (1MB max)";
  19. }
  20. if(count($errorList)<1){
  21. $file_ext = preg_split("/\./",$filename);
  22. $allowed_ext = preg_split("/\,/",$allowed_ext);
  23. $rand = rand(100,999).rand(10,99).rand(100,500);
  24. $front_name = substr($file_ext[0], 0, 15);
  25. $newfilename = $front_name."_".$rand.".".end($file_ext);
  26. foreach($allowed_ext as $ext){
  27. if($ext==end($file_ext)){
  28. $data = date("d.m.Y");
  29. $zapis = mysqlCountR("mmvet_obqvi", "date = '$data' AND userip = '$ip' AND active = 0");
  30. if($zapis > 0){
  31. $picsB = mysqlGet("mmvet_obqvi", "*", 0, "date = '$data' AND userip = '$ip' AND active = 0");
  32. $allpics = $picsB['pics'];
  33. $picsEx = explode(",", $allpics);
  34. if(sizeof($picsEx) == 5){
  35. echo "You can't upload more than 5 pictures!";
  36. }else{
  37. $plusPic = $allpics.",".$newfilename;
  38. mysqlSet("mmvet_obqvi", "pics", "$plusPic", "date = '$data' AND userip = '$ip' AND active = 0", "~ ");
  39. }
  40. }else{
  41. mysqlAdd("mmvet_obqvi", "null,null,null,null,null,null,$data,null,null,null,null,null,null,null,null,$newfilename,$ip,0");
  42. }
  43. if(sizeof($picsEx) <= 5 ){
  44. copy($_FILES['pic']['tmp_name'], "_data/uploads/".$newfilename);
  45. saveThumb("_data/uploads/".$newfilename, 283, 212, "_data/uploads/thumbbig_".$newfilename, end($file_ext));
  46. saveThumb("_data/uploads/".$newfilename, 108, 81, "_data/uploads/thumbsmall_".$newfilename, end($file_ext));
  47. unlink("_data/uploads/".$newfilename);
  48. $imgUploaded = true;;
  49. }
  50. }
  51. }
  52.  
  53. }else{
  54. $imgUploaded = false;
  55. }
  56. }else{
  57. echo "No file chosen!";
  58. $imgUploaded = false;
  59. }
  60. }else{
  61. echo "No file!";
  62. }
  63. ?>
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 35
Reputation: anish.anick is an unknown quantity at this point 
Solved Threads: 3
anish.anick anish.anick is offline Offline
Light Poster

Re: Refresh after uploading is done

 
0
  #2
May 5th, 2009
Catch the ajax on complete state when the readyState property becomes 4, after that execute the javascript code window.location.reload() to refresh/reloading the page

Regards
Anish
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 9
Reputation: trevata is an unknown quantity at this point 
Solved Threads: 0
trevata trevata is offline Offline
Newbie Poster

Re: Refresh after uploading is done

 
0
  #3
May 5th, 2009
Yeah. But here I don't have an XMLHTTP Object And I don't know how the javascript understands when the uploading is done
Last edited by trevata; May 5th, 2009 at 10:25 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC