Jump to content

Showing insert process for multiple entries during import of uploaded file


SuperMyKel

Recommended Posts

This may seem kind of convoluted, but I am regularly uploading and importing an excel spreadsheet to a web application written in php/mysql. I would like to see the progress of the process while the spreadsheet is read in, parsed and inserted into the database.

 

Short synopsis of the process.

File is uploaded via form

File is parsed via php line for line

  for each line some criteria are evaluated

    if pass then insert

    else go to next line of spreadsheet

 

I would like to see a display of the process, progress bar, display of spreadsheet data currently being inserted, that sort of thing.

 

I have tried to wrap my head around the process, but can't quite figure out how to do it with the current script that I have as it is all done in one script, and I can't see how it would answer the ajax calls to display each successive insert.

 

Thanks in advance for any help you might have.

Link to comment
Share on other sites

You can use javascript for the updates, executing a function that updates some for of user interface.  To make a percent, you would need the total lines to be evaluated.  Pass that to a javacript function

 

function setComplete(total){
GLOBAL_total=total}

and you would need to have placed GLOBAL_total and GLOBAL_curPos before the <body> inside a <script>

then after every (or maybe every 10--don't know how many lines were talking) execute a:

function setCurPos(pos){
GLOBAL_curPos=pos
updateUI()
}

function updateUI(){
document.getElementByid("progress").innerHTML=(GLOBAL_curPos/GLOBAL_total)
}
[code]
This will all work if you have a <DIV id="progress"></DIV> somewhere on your php page (before you start executing the upload/processing)

Again on every line you are going to have to:
[code=php:0]
echo "<script language=\"javascript\">\n setCurPos($i)\n</script>";
$i++;

 

This probably isn't super efficient, but there is going to be overhead.  To do what you want.[/code]

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.