djbuddhi Posted July 24, 2008 Share Posted July 24, 2008 i need a AJAX php image upload script ? for upload a small image by AJAX ,i know how to do it in other method but problem when using AJAx .Pls help :) Quote Link to comment Share on other sites More sharing options...
atholon Posted July 25, 2008 Share Posted July 25, 2008 I would like to know this as well. There seem to be a lot of crappy ones out there. Most use a hidden Iframe to do the upload. Many other sites use Java Applets for file management. I don`t like that method in some circumstances because the applets take a while to load sometimes. FYI this would bee a great question to address in a sticky... Searching around I have found this one: http://www.webtoolkit.info/ajax-file-upload.html Quote Link to comment Share on other sites More sharing options...
atholon Posted July 26, 2008 Share Posted July 26, 2008 Ok I was just testing out my script to see if it would work, here is an easy way to do it. You will need to modify it if you want a progress bar and fancy stuff. This technically doesn`t use Ajax. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>{title}</title> <script type="text/javascript" src="uploader.js"></script> <script type="text/javascript"> window.onload = init; </script> </head> <body> <form method="post" enctype="multipart/form-data" id="uploadform"> <input type="file" name="thefile" size="30" class="fileinput"/><a href="#" class="uploadfile">Upload File</a> </form> <iframe src="" id="fileframe" name="fileframe"></iframe> </body> </html> function init() { fileUploadEvents(); } function fileUploadEvents() { var links = document.getElementsByTagName("a"); if (links) { for (var x=0; x<links.length; ++x) { if (links[x].className == "uploadfile") links[x].onclick = uploadFile; } } } function uploadFile() { var uploadForm = document.getElementById("uploadform"); if (uploadForm) { uploadForm.target="fileframe"; uploadForm.action="uploadme.php"; } uploadForm.submit(); } <?php print_r($_FILES['thefile']); $theFile = $_FILES['thefile']; $tmp_name = $theFile['tmp_name']; $oldname = strtolower($theFile['name']); $name = strtolower($theFile['name']); echo ("<br>File Name:$name<br>"); $ext = substr(strrchr($name, "."), 1); echo ("<br>File Extention:$ext<br>"); $error = move_uploaded_file($tmp_name, "hamburger/$name"); echo "Column:".$iColumn; echo "Your file" . $oldname . " was uploaded to ". $actualfilelocation; ?> Quote Link to comment Share on other sites More sharing options...
djbuddhi Posted July 28, 2008 Author Share Posted July 28, 2008 thank u very much Quote Link to comment Share on other sites More sharing options...
atholon Posted July 28, 2008 Share Posted July 28, 2008 np, you might want to look into a java applet uploader if you are looking to upload large images. also, my code will throw warnings because I basically recycled part of one of my old upload scripts Just neeed to get rid of the bottom part. echo "Column:".$iColumn; echo "Your file" . $oldname . " was uploaded to ". $actualfilelocation; also this line of the JS should be inside of the if "uploadForm.submit();" Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.