Jump to content

PHP & AJAX upload & progress

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
Hi there,

Currently working on a script to show the progress of an upload using PHP and AJAX. How would this be possible? Because my script doesn't seem to work, tried something like this:

<form method="POST" id="uploadForm" action="<?=$_SERVER['PHP_SELF'];?>" enctype="multipart/form-data" onSubmit="uploadProg()">
<input type="file" name="uploadfile">
<input type="button" value="Upload File!" name="upload" onClick="document.forms['uploadForm'].submit();">
</form>

<div id="uploadProg">

</div>

But upon submitting the form, the page refreshed and the uploadProg() ajax function ( which calls the PHP script to upload the file ) was not executed..

Could someone please help me?

Thanks in advanced!

#2
SoN9ne

SoN9ne

    Programmer

  • Members
  • PipPipPipPip
  • 129 posts
If you use this:
onSubmit="return uploadProg();"
You can prevent the page from submitting by returning false.

Since the page submits and the function never gets called, this could indicate an error in the js. Use firebug to isolate the error.
Are you using firebug? Check to see if you get any console errors.
Set a break point in uploadProg() and step through each line until you notice the issue.

#3
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
Thanks a lot :)

Will have a look into Firebug too, would make it lot easier with all small javascript bugs in my scripts ;D

Though, I think I'll be using SWFUpload which I found posted on another website which seems to be doing this job (progress bar of uploading) great!

And as I'm more of a PHP/MySql coder than javascript, such scripts can come handy to me ^^

Cheers.