| | |
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
![]() |
•
•
Join Date: Apr 2008
Posts: 9
Reputation:
Solved Threads: 0
Hi. In short, how can I make this javascript to refresh the page when uploading is done ?
If you need the php file:
javascript Syntax (Toggle Plain Text)
function $m(theVar){ return document.getElementById(theVar) } function remove(theVar){ var theParent = theVar.parentNode; theParent.removeChild(theVar); } function addEvent(obj, evType, fn){ if(obj.addEventListener) obj.addEventListener(evType, fn, true) if(obj.attachEvent) obj.attachEvent("on"+evType, fn) } function removeEvent(obj, type, fn){ if(obj.detachEvent){ obj.detachEvent('on'+type, fn); }else{ obj.removeEventListener(type, fn, false); } } function isWebKit(){ return RegExp(" AppleWebKit/").test(navigator.userAgent); } function ajaxUpload(form,url_action,id_element,html_show_loading,html_error_http){ var detectWebKit = isWebKit(); form = typeof(form)=="string"?$m(form):form; var erro=""; if(form==null || typeof(form)=="undefined"){ erro += "The form of 1st parameter does not exists.\n"; }else if(form.nodeName.toLowerCase()!="form"){ erro += "The form of 1st parameter its not a form.\n"; } if(erro.length>0){ alert("Error in call ajaxUpload:\n" + erro); return; } var iframe = document.createElement("iframe"); iframe.setAttribute("id","ajax-temp"); iframe.setAttribute("name","ajax-temp"); iframe.setAttribute("width","0"); iframe.setAttribute("height","0"); iframe.setAttribute("border","0"); iframe.setAttribute("style","width: 0; height: 0; border: none;"); form.parentNode.appendChild(iframe); window.frames['ajax-temp'].name="ajax-temp"; var doUpload = function(){ removeEvent($m('ajax-temp'),"load", doUpload); var cross = "javascript: "; cross += "window.parent.$m('"+id_element+"').innerHTML = document.body.innerHTML; void(0);"; $m(id_element).innerHTML = html_error_http; $m('ajax-temp').src = cross; if(detectWebKit){ remove($m('ajax-temp')); }else{ setTimeout(function(){ remove($m('ajax-temp'))}, 250); } } addEvent($m('ajax-temp'),"load", doUpload); form.setAttribute("target","ajax-temp"); form.setAttribute("action",url_action); form.setAttribute("method","post"); form.setAttribute("enctype","multipart/form-data"); form.setAttribute("encoding","multipart/form-data"); if(html_show_loading.length > 0){ $m(id_element).innerHTML = html_show_loading; } form.submit(); }
php Syntax (Toggle Plain Text)
<?php include "config.php"; @header("Content-Type: text/html; charset=windows-1251"); $fileN = $_REQUEST['pic']; if (isset($fileN)){ $allowed_ext = "jpg,jpeg,gif,png"; $filesize = $_FILES['pic']['size']; $maxlimit = 9999999999; if($filesize > 0){ $filename = strtolower($_FILES['pic']['name']); $filename = preg_replace('/\s/', '_', $filename); if($filesize < 1){ $errorList[] = "Empty file!"; echo "Empty file!"; } if($filesize > $maxlimit){ $errorList[] = "File too big!"; echo "File too big! (1MB max)"; } if(count($errorList)<1){ $file_ext = preg_split("/\./",$filename); $allowed_ext = preg_split("/\,/",$allowed_ext); $rand = rand(100,999).rand(10,99).rand(100,500); $front_name = substr($file_ext[0], 0, 15); $newfilename = $front_name."_".$rand.".".end($file_ext); foreach($allowed_ext as $ext){ if($ext==end($file_ext)){ $data = date("d.m.Y"); $zapis = mysqlCountR("mmvet_obqvi", "date = '$data' AND userip = '$ip' AND active = 0"); if($zapis > 0){ $picsB = mysqlGet("mmvet_obqvi", "*", 0, "date = '$data' AND userip = '$ip' AND active = 0"); $allpics = $picsB['pics']; $picsEx = explode(",", $allpics); if(sizeof($picsEx) == 5){ echo "You can't upload more than 5 pictures!"; }else{ $plusPic = $allpics.",".$newfilename; mysqlSet("mmvet_obqvi", "pics", "$plusPic", "date = '$data' AND userip = '$ip' AND active = 0", "~ "); } }else{ mysqlAdd("mmvet_obqvi", "null,null,null,null,null,null,$data,null,null,null,null,null,null,null,null,$newfilename,$ip,0"); } if(sizeof($picsEx) <= 5 ){ copy($_FILES['pic']['tmp_name'], "_data/uploads/".$newfilename); saveThumb("_data/uploads/".$newfilename, 283, 212, "_data/uploads/thumbbig_".$newfilename, end($file_ext)); saveThumb("_data/uploads/".$newfilename, 108, 81, "_data/uploads/thumbsmall_".$newfilename, end($file_ext)); unlink("_data/uploads/".$newfilename); $imgUploaded = true;; } } } }else{ $imgUploaded = false; } }else{ echo "No file chosen!"; $imgUploaded = false; } }else{ echo "No file!"; } ?>
![]() |
Similar Threads
- Problems uploading with Dreamweaver CS3 (HTML and CSS)
- uploading image folder (Graphics and Multimedia)
- problem with uploading several images with the same name. (ASP.NET)
- Email code check only showing on second page refresh! Can't figure this (PHP)
- Can a text link pass php variables? (PHP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Is this possible?
- Next Thread: Need help in country, state drop down
| Thread Tools | Search this Thread |
ajax ajaxexample ajaxjspservlets api array browser bug captcha captchaformproblem cart checkbox child class close codes cookies createrange() cursor date debugger dependent developer disablefirebug dom dropdown editor element embed engine events explorer ext file firefox form forms getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe images internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl maps marquee masterpage math matrixcaptcha media object onerror onmouseoutdivproblem onreadystatechange parent paypal pdf php position post programming progressbar prototype rated redirect runtime safari scale scriptlets scroll search security session shopping size software star stars synchronous toggle tweet unicode variables web webservice wysiwyg \n






And I don't know how the javascript understands when the uploading is done