homepage Welcome to WebmasterWorld Guest from 54.226.10.234
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
File upload script with progress bar?
Need proper file upload script
majjk

10+ Year Member



 
Msg#: 4017448 posted 11:12 am on Nov 2, 2009 (gmt 0)

Hi,
I'm sure most of you are aware of the poor support php has (at least until recently) for upload progress tracking. Apparantly there is something in place that should make it possible to write a progress bar... the only problem is that at the same time my server uses write-caching, which basically kills off this long awaited php feature. Before someone says anything, I'm on shared hosting, so I'll have to live with write-caching

This is what I would like: a file upload script with a progress bar and that can handle all sort of issues, such as duplicate file name, illegal file extensions etc.

In my desperation I have tried almost every script I have bumped into the last couple of years, including commercial ones.

I have used uberuploader for a while, where the progress bar is not showing, so displaying an animated gif instead. not good... I've also tried FancyUpload which only works partly... not sure what the problem is there.

How have you people solved this?

 

dreamcatcher

WebmasterWorld Senior Member dreamcatcher us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4017448 posted 12:43 pm on Nov 2, 2009 (gmt 0)

Google 'uploadify'. That might be of some use.

dc

majjk

10+ Year Member



 
Msg#: 4017448 posted 4:08 pm on Nov 2, 2009 (gmt 0)

I did actually try it earlier this morning, but I have the same problem with that as with fancyupload, i.e. on windows vista the progress bar goes up to 100% in about a second (using a 4.8mb file. The upload never seem to actually complete even though it indicates 100%). On my windows xp uploading the same file takes about a minute, and the progress bar works fine. Both xp and vista are using FF 3.5.4 (it's the same case for IE).

Do you have alternative suggestions, or do you perhaps know what could be the problem with uploadify and fancyupload on my vista?

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4017448 posted 5:21 pm on Nov 2, 2009 (gmt 0)

I've chased this on and off over the years in Perl, PHP, ASP . . . think about it for a second.

- Percentage is easy. Total file size / amount received. The problem is in, "what's the total file size?"

- You cannot access the initial file upload size because browsers disallow any Javascript manipulation of the object. If you could, it would be a **major** security hole, allowing abuse of the file upload object to sniff the user's system.

- You have to move this file to the server, and that is the only place you can control the received file. But how can you know what the TOTAL file size is before it arrives?

You can't.

The closest I ever got was using fork() to fork the upload in a child process, inserting a small iframe in the upload page that checked the process ID of the upload and was able to report total bytes uploaded. But as a "progress meter" it was a huge waste of time without knowing the full file size.

Most of the progress meters out there are "fluff and mirrors" and have nothing to do with actual file upload progress. They are configurable, meaning, extend or shorten the length of time allowed for upload. So what you'd do is "fake it" by futzing around with this until it gets close.

Then you send it to the client who has a different connection speed and it all falls down.

But there is a "workaround."

Throw a small animation on the page "uploading, please wait . . . " Put it in a hidden div.

On submit of the form for upload, show the div using Javascript. So it will sit there and animate, giving the impression it's in the works - and is a far cry more "honest" than fiddling about with a fluff meter.

When the upload completes, your script returns a success response, replacing the upload page and returning the form for upload another (or whatever.) This re-hides the uploading div.

I've been watching the PHP progress meter issue too, and wonder just how in the hell they are going to pull that off. Would be great if they can.

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4017448 posted 1:31 am on Nov 3, 2009 (gmt 0)

Forgot to add - Flash uploaders can do this as they don't use the file upload object and can get the size of the data loaded. The .swf loads the local file into itself and you can get the total before upload. Then on send to the server you can meter the progress. Of course, this makes it Flash dependent, which is probably the least problematic.

majjk

10+ Year Member



 
Msg#: 4017448 posted 9:31 am on Nov 3, 2009 (gmt 0)

Do you have any good suggestions for flash uploaders? I'm about to implement uberuploader without the bar, just an animated gif, which is really rubbish for larger uploads. No indication of progress...

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4017448 posted 7:54 pm on Nov 3, 2009 (gmt 0)

Others might, try the Flash forum - I don't, as I roll my own and seldom scour the web for free/open source stuff.

JohnCanyon

10+ Year Member



 
Msg#: 4017448 posted 8:17 pm on Nov 3, 2009 (gmt 0)

This is possible using PHP, that being said you will likely not be able to take advantage via your shared host.

You can leverage APC or uploadprogress PECL extensions.

An important note to any upload tracking is you want to ensure that you are not in a current session. One way to ensure that your not writing to the session is to call: session_write_close(); at the beginning of your script.

As has been stated flash uploads are probably your best bet via your shared situation.

Good Luck,

JC

majjk

10+ Year Member



 
Msg#: 4017448 posted 9:08 pm on Nov 3, 2009 (gmt 0)

I actually had my webhost to install APC today. I'm gonna see what I can do with that in place.

JohnCanyon

10+ Year Member



 
Msg#: 4017448 posted 9:48 pm on Nov 3, 2009 (gmt 0)


I actually had my webhost to install APC today. I'm gonna see what I can do with that in place.

You could take a look at Zend Frameworks ProgressBar class.

I believe it's called Zend_ProgressBar.

JC

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4017448 posted 7:25 pm on Nov 4, 2009 (gmt 0)

I've been watching that . . . it says it will project an ETA, but I didn't dig too deep into the draft to see how it's going to work, does anyone have references?

JohnCanyon

10+ Year Member



 
Msg#: 4017448 posted 10:23 pm on Nov 4, 2009 (gmt 0)


I've been watching that . . . it says it will project an ETA, but I didn't dig too deep into the draft to see how it's going to work, does anyone have references?

References to what exactly? Are you referring to Zend Framework, APC, upload progress?

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4017448 posted 3:35 am on Nov 5, 2009 (gmt 0)

LOL . . . yes, sorry, the Zend Frameworks ProgressBar, it was the bottom of page 1 and when I saw my Q was on page two . . . was too tired to edit and quote. :-)

JohnCanyon

10+ Year Member



 
Msg#: 4017448 posted 7:07 pm on Nov 6, 2009 (gmt 0)

Hehe.. no problem.

I have successfully gotten it to work with Zend_ProgressBar utilizing the JSPull adapter and the uploadprogress PECL extension.

I am working on a write up for it now talking about multiple files and how it works. There are several tutorials out there for uploading a single file.

If you would like I will PM you with a link when the article is complete.

Cheers.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved