Jump to content

i need a AJAX php image upload script ?


djbuddhi

Recommended Posts

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

Link to comment
Share on other sites

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;
  
?>

 

Link to comment
Share on other sites

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();"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.