0

I am planning to implement XML Sitemap Generation, User will enter URL, than PHP script will generate XML file, PHP script will track the XML generation from Max URL completion, for ex:once it reaches 100 URL, XML file will be created and prompt User to download the file.

Now, How I can show real time Progress to User in Webpage, and once complete, XML file will be downloaded to Client desktop.

$depth = 100; --> To track completion.

$map_row = "<url>\n";
$map_row .= "<loc>$url</loc>\n";
if ($enable_frequency) {
    $map_row .= "<changefreq>$freq</changefreq>\n";
}
if ($enable_priority) {
    $map_row .= "<priority>$priority</priority>\n";
}
if ($modified) {
    $map_row .= "   <lastmod>$modified</lastmod>\n";
}
$map_row .= "</url>\n";
fwrite($file_stream, $map_row);
$indexed++;

....
...
....

// Begin by crawling the original url
scan_url($real_site);
// Finalize sitemap
fwrite($file_stream, "</urlset>\n");
fclose($file_stream);
header('Content-disposition: attachment; filename=sitemaptest.xml');
readfile('sitemaptest.xml');
die; //modified code  

Submit Form button as follows :

<form class="form-horizontal" method="post">
<textarea class="form-control" name="url" placeholder="Enter URL to Submit"></textarea>
<br>
<input class="form-control btn btn-warning" type="submit">
</form>
techexpert
  • 11
  • 5
  • https://stackoverflow.com/a/1802777 – Tim Morton Jan 11 '20 at 20:52
  • @TimMorton don't think that will work in the case of a file download, because when it gets those headers, the browser redirects the response data away from the web page and onto the user's disk instead. – ADyson Jan 11 '20 at 21:32
  • @ADyson I haven’t done a progress bar in a long, long time... but I’m inclined to agree with you. I didn’t read the question thoroughly. A progress bar would probably only work for the calculation part, and then you’d have to redirect in order to issue another header to download to the user, if that’s even possible. Is it worth the hassle? For me it is not; I’d just slap a loading gif on the page until it finishes... – Tim Morton Jan 11 '20 at 22:09
  • @TimMorton Even then I think you'd need AJAX for the first request. Otherwise again, due to the redirection of the response onto the disk, the page would have no way to know when the request was complete and hide the gif again. I think it needs to go like this: AJAX request to start processing and production of the file, file saved to disk, server returns link to new document. JS receives link in AJAX response and does a client-side navigation to that link (e.g. using `location.href`) in order to trigger the download. And yeah a loading gif to animate during the AJAX request. – ADyson Jan 12 '20 at 21:00

0 Answers0