473,396 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Image upload with progress bar or please wait screen.

AaronL
99
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??
Apr 28 '10 #1
5 8385
code green
1,726 Expert 1GB
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.
Apr 28 '10 #2
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.
Apr 28 '10 #3
AaronL
99
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.
May 1 '10 #4
chathura86
227 100+
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
May 1 '10 #5
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.
Expand|Select|Wrap|Line Numbers
  1. <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.)
Expand|Select|Wrap|Line Numbers
  1. function showLoading() {
  2.     // Create a white box to cover the page.
  3.     var back = document.createElement('div');
  4.     back.style.backgroundColor = '#ffffff';
  5.     back.style.position = 'fixed';
  6.     back.style.zIndex = '0';
  7.     back.style.left = '0px';
  8.     back.style.top = '0px';
  9.     back.style.right = '0px';
  10.     back.style.bottom = '0px';
  11.     document.body.appendChild(back);
  12.  
  13.     // Add a box to contain the message.
  14.     var box = document.createElement('div');
  15.     box.style.position = 'absolute';
  16.     box.style.zIndex = '1';
  17.     box.style.width = '250px';
  18.     box.style.margin = '15px ' + ((document.body.offsetWidth / 2) - (250 / 2)) + 'px';
  19.     box.style.fontFamily = 'Verdana, Arial, serif';
  20.     document.body.appendChild(box);
  21.  
  22.     // Add the "Please wait" header
  23.     var message = document.createElement('span');
  24.     message.id = 'loading_header';
  25.     message.style.display = 'block';
  26.     message.style.fontSize = '175%';
  27.     message.style.fontWeight = 'bold';
  28.     message.style.textAlign = 'center';
  29.     message.innerHTML = 'Please wait';
  30.     box.appendChild(message);
  31.  
  32.     // Add the subheader message
  33.     var message = document.createElement('span');
  34.     message.id = 'loading_message';
  35.     message.style.display = 'block';
  36.     message.style.fontSize = '125%';
  37.     message.style.textAlign = 'center';
  38.     message.innerHTML = 'Your files are being uploaded.';
  39.     box.appendChild(message);
  40.  
  41.     // Add a loading image.
  42.     var img = document.createElement('img');
  43.     img.setAttribute('src', './loading.gif');
  44.     img.style.display = 'block';
  45.     img.style.width = '64px';
  46.     img.style.height = '64px';
  47.     img.style.margin = '15px auto';
  48.     box.appendChild(img);
  49. }
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.
May 1 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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"...
4
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...
0
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...
15
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...
0
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...
6
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...
5
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...
3
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...
4
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,...
10
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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...
0
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.