I found a great client side image resize solution:
http://www.resize-before-upload.com/

but the free version doesn't have form integration, so I copied some ajax code off the internet and integrated it into my PHP - so it

just keeps checking for a specific file to be uploaded and then the PHP just echos 'success' and if the ajax sees that it redirects to

another page to continue the process

Here's the JS (Jquery obviously)

$(document).ready(function()
{
   //filecheck.php is called every 2 seconds to ask server if file has been uploaded yet
   var refreshId = setInterval(function()
   {
   $('#Davfilecheck').load('scripts/filecheck.php');
   
   var fc1 = new String();
   fc1 = document.getElementById('Davfilecheck').innerHTML;

if (fc1 == "Success!"){
alert ("The photo has been successfully uploaded to the site. Click OK to enter details for photo");
window.location="index.php?locate=upload&filedone=yes";
}


   }, 2000);

});

And here's the 'filecheck.php' code

<?php
if (file_exists('../secure/uploads/uploadfile')){echo "Success!";}
?>

This system works great with most newer browsers but when the file is uploaded in IE6 the JS doesn't seem to notice.

I will upload my main PHP script if necessary but I'm pretty sure this is the part that won't work in IE6.

Is the only option to ask the users to upgrade browser or is there a hack for getting this to work in IE6 ?

P.S. I've also noticed lately that on some browsers the code loops around a second time, causing problems. It must be terrible code - I'm sorry but my PHP coding is a lot better than my JS coding. :-D

If anybody knows a more efficient way to do this I would really appreciate it.

Thanks

Davil,

IE6 certainly does do AJAX.

I think you would be better off avoiding setInterval().

Better to make your "upload" http request into an AJAX call, with a response handler that simply displays (or alerts) the response string.

You will then need to arrange for a php page to handle the upload request and to return "success"|"fail"|"timeout"|whatever.

Thus, all the "has it finished yet" testing is coordinated server-side, not client-side. Much simpler.

Airshow

Hmmm... I've been doing some googling and got it working (at least it looks like it's working) -

if (!XMLHttpRequest) {
  window.XMLHttpRequest = function() {
    return new ActiveXObject('Microsoft.XMLHTTP');
  }
}

I put that code in before my own and it seems to be working. I only half understand what you're saying Airshow and I'll try to get to grips with it because I want the site to be as efficient and cross browser as possible. Thanks

Davil,

You shouldn't need that code in your last post id you are using jQuery, which has AJAX support built in. See the jQuery API to see how to drive it.

Slight change of direction cw. my earlier post ...

From what I have read, a lot of people choose to use one of several jQuery plugins to handle a file upload (enctype="multipart/form-data" ). These plugins make life easier than trying to work with raw jQuery and (if you choose the right one) will handle feedback to the user on progress.

jQuery plugins tend to be well documented and there's every chance you will find one with sample php to demonstrate what is required server-side.

I'm afriad you will need to do some research yourself as I only know in principle about this aspect of jQuery - I have never done it for real.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.