Extract zip with progress bar in PHP or RUBY
is there a way to call an ajax function that calls a php that extract a file and send progress via httpres开发者_StackOverflowponse so i can make a progress bar?
I know php is not a multithreading language so i'm learning ruby and i've seem some extract zip examples but have no idea about how can i know the progress of the file, maybe a new thread???
So any solution or idea either php or ruby is really welcome.
Thank you very much
You can use ruby ProgressBar gem and net/http
to do this.
Here is the demo code:
url_base = ''
url_path = ''
@counter = 0
Net::HTTP.start(url_base) do |http|
response = http.request_head(URI.escape(url_path))
puts (response['content-length'].to_i/(1024*1024)).to_s << 'M'
pbar = ProgressBar.new("file name:", response['content-length'].to_i)
File.open("test.file", 'w') {|f|
http.get(URI.escape(url_path)) do |str|
f.write str
@counter += str.length
pbar.set(@counter)
end
}
end
pbar.finish
puts "Done."
精彩评论