Hello,
I wrote a program that uploads images to a website using PHP but I'm not liking
how it's currently working.
When the user hits submit, the browser takes a long time, which I know is normal
because it's uploading images, however, I need to write a way to make it show
a progress bar, or at least say "uploading images please wait..."
I was thinking I would make imageuploader.php and then pass a $_GET value
with the progress with all of the files posted hidden, after the user chooses
which files to upload. I figured I'd have it upload one file at a time, and use the
header() function to move it to the next step and upload the 2nd file, but I realized
that wouldn't work because header would give me that "header already created"
type error.
The software I'm writing (hopefully) will be very professional and popular, but I
don't want my image uploader to be crap.
Any advice out there??
5 8385
I have noticed a few people looking for a 'real' time progress bar but it seems to be difficult.
You can perform a simple cheat and use a moving-gif in the HTML to make the user feel comfortable.
Or there are a few Javascript classes that simulate a progress bar.
xp_progress.js is one I use.
Atli 5,058
Expert 4TB
This is one of those major failures all the browser manufacturers share in. The displaying of the progress of a file upload should of course be the responsibility of the browser itself. We should not need to resort to some JavaScript hacks or static (read: fake) animated images to make it "appear" as if there is actually some progress display going on.
But hey, it's not like we're not used to covering for the shortcomings of the browsers... (Some more than others.)
On a more practical note, to actually display the status of a file upload, you would need a HTTP server module that is capable of relaying the status back to the browser as the data comes in. And of course the client-side code to receive and display the data. -- Not exactly something you just slap together for the sake of it.
A better approach is to just display a "loading" image, with a "Please wait..." header, that lets the user know something is happening, even though the progress of what is going on is nowhere to be seen.
Ok, well what I'd like to do is bring up the upload screen where you browse for files, and when
you click on the upload button, it brings it up to another screen that says please wait, then after they're done uploading, I want it to return to another page.
How can I do that because if I submit to the next page from the browse for files page, and then bring up the please wait page, if I use the header() command to redirect after the upload, it will give me the header already created message or something.
I'm most likely thinking of the wrong methods to do this.
go through this manual, i managed to create a real time upload progress bar with this module (with the help of ajax). http://php.net/manual/en/book.apc.php
but the downside is most hosting servers does not support this extension yet
and i did not found a windows version of the module.
so make sure of that. other than that it works perfectly
Regards
Atli 5,058
Expert 4TB @chelf
That's not something you can do with PHP alone. The PHP code is only executed after the request has been completely received (including the files). What you need to do is have JavaScript display the "Please wait" message when you click on the upload button, before the form is submitted.
The simples way to do that is to attach a function to the form's submit event that changes the contents of the page and the returns true. - <form action="process.php" onsubmit="showLoading()">
And then have the showLoading function create the elements for the "Please wait" message. (I copied this from an old project of mine.) - function showLoading() {
-
// Create a white box to cover the page.
-
var back = document.createElement('div');
-
back.style.backgroundColor = '#ffffff';
-
back.style.position = 'fixed';
-
back.style.zIndex = '0';
-
back.style.left = '0px';
-
back.style.top = '0px';
-
back.style.right = '0px';
-
back.style.bottom = '0px';
-
document.body.appendChild(back);
-
-
// Add a box to contain the message.
-
var box = document.createElement('div');
-
box.style.position = 'absolute';
-
box.style.zIndex = '1';
-
box.style.width = '250px';
-
box.style.margin = '15px ' + ((document.body.offsetWidth / 2) - (250 / 2)) + 'px';
-
box.style.fontFamily = 'Verdana, Arial, serif';
-
document.body.appendChild(box);
-
-
// Add the "Please wait" header
-
var message = document.createElement('span');
-
message.id = 'loading_header';
-
message.style.display = 'block';
-
message.style.fontSize = '175%';
-
message.style.fontWeight = 'bold';
-
message.style.textAlign = 'center';
-
message.innerHTML = 'Please wait';
-
box.appendChild(message);
-
-
// Add the subheader message
-
var message = document.createElement('span');
-
message.id = 'loading_message';
-
message.style.display = 'block';
-
message.style.fontSize = '125%';
-
message.style.textAlign = 'center';
-
message.innerHTML = 'Your files are being uploaded.';
-
box.appendChild(message);
-
-
// Add a loading image.
-
var img = document.createElement('img');
-
img.setAttribute('src', './loading.gif');
-
img.style.display = 'block';
-
img.style.width = '64px';
-
img.style.height = '64px';
-
img.style.margin = '15px auto';
-
box.appendChild(img);
-
}
The process.php code can then process the files and redirect to whatever page you want displayed when the upload is complete. If you keep getting a "Headers already sent" message when trying to redirect, read this article.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brian Birtle |
last post by:
**** A CHALLENGE TO THE GURUS - refute the statement "It's impossible
to build a file upload progress meter using ASP.NET" **** First person
to prove me wrong gets "All Time .NET Programming GOD"...
|
by: Kenneth Keeley |
last post by:
Hi,
I have a page that uploads files to my server and I wish to display a
"Please wait while uploading" page to the user while the file is uploading.
I have been able to redirect the user once the...
|
by: Manuel |
last post by:
I have a page that uploads a file to the user. Since the file is created on
the fly and it takes a few seconds to generate, I present a "Please Wait"
screen until the file is uploaded. This is the...
|
by: David Lozzi |
last post by:
Howdy,
I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders!
Now I am making a public function that will take the...
|
by: nidhig |
last post by:
Hi
I am trying to implement the Abort functionality in progress bar
control. Scenario is like this.
I have a web application which performs a very long computation
process. This computation...
|
by: Marko Vuksanovic |
last post by:
I am trying to implement a file upload progress indicator (doesn't have to be a progress bar) using atlas... I do realize that the indicator cannot be implemented using Update panel control, but is...
|
by: LtCommander |
last post by:
Hello all,
1. I am a little new to ASP.NET, so please bear with me.
2. I am trying to create a very simple website which requires an upload
box (end user file sizes may be anywhere between 1MB...
|
by: Ken1 |
last post by:
Hello,
Does anyone know of an easy to implement ajax upload script for php
which also has a progress bar. If possible I'd like it to be able to
remove already uploaded files and do minor...
|
by: yatin |
last post by:
hi, friend. i have a problem in image validation plz check it.
i have to include a image validation in foam 1. but i sending a details through form2.
But when i include a image validation in foam1,...
|
by: mishrarajesh44 |
last post by:
hii all,
I am facing a problem currently..
i have a script for image uploading and resizing..
the image uploading takes place properly for every size images..
but, the resizing works for...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |