progress bar while uploading image without ajax in php - php

I am uploading a file on my website. It works fine. Now i want to display progress bar while it take time in uploading.
I have option to chenge uploading through ajax, but i can not use ajax. Can it possible to show without using ajax and without disturbing the code.
$image = new SimpleImage();
$objdjs= new Djs;
if(isset($_POST['btnprofile']))
{
if($_FILES['profilegallery']['name']!=""){
$res1 = $objdjs->upload_file($_FILES['profilegallery'],PATH_PROFILE_IMAGE);
$image->load(PATH_PROFILE_IMAGE.$res1);
$image->resize(46,36);
$image->save(PATH_PROFILE_IMAGE."thumb_".$res1);
$title=trim($_POST['title1']);
$ins = $objdjs->insertprofile($uid,$title,$res1);
$messageProfile="<span style='color:#336600'>Image has been added in profile gallery</span>";
echo "<script>window.location='listprofilegallery.php?ms=true';</script>";
any help will be appricated
Thanks

You can try SWFUpload, it does have a customizable progress bar, but this only works with flash. There's also a jQuery plugin called uploadify

The very ugly but fast solution is to put an iframe that refreshes itself.
Why not use Ajax?

You talk about not changing the code (much), so I think the easiest option is (eugh) a flash uploader. When you say "but I cannot use AJAX" I'm going to assume you mean "I don't know how to use it yet". In this case, I'd recommend jQUery and AJAX. You still couldn't have a progress bar (unfortunately), but it will help you learn AJAX.

I think what your asking is basically impossible, when your user would submit the form you would be stuck. Then only way to create some upload progress bar is
javascript/ajax
flash
java applet

What you want to do is impossible with just PHP. PHP is a server-side language that cannot directly effect the page once it has been served to the browser. You would need some Javascript to do this, AJAX really.
There are two good options:
use swf
use AJAX

Related

Best way to make an ajax uploading file?

I want make an uploading system with ajax [none page reload]
I have search on google, found some thing, upload in iframes , File API etc...
Old browsers havent file API, and I have some problems with iFrame uploading in IE ,
Is there any way to make it with working in all browsers?
Since your tags include jquery, I would suggest that the best solution for you would be the jQuery Form Plugin.
This plugin makes it very easy to work with forms via ajax, including forms with file upload fields. You don't need to worry about the browser API or whether it supports it or not; the plugin deals with all that behind the scenes.
There are good examples on the plugin's website, and I can confirm it works well as I've just implemented it in a project myself.
Hope that helps.
Use Uploadify. It's really simple and looks great.
http://www.uploadify.com/

PHP File Upload No Page Refresh

I know this has been asked by a few people but I haven't seen the answer. I have a php upload form for a file upload in a div tag. Is it possible to submit the form and upload the file without a page refresh? I haven't found the plugins to work because I want to submit the form with a title and other data attached as well. Any suggestions? I looked at using an iframe, but i'm not sure it will work in an upload.php wrapped in a div tag?
Here is the most simple solution you can use: Image upload without page refresh.
No obligation to use the javascript part, but it gives you the opportunity to show a notice that the transfer has been correctly done.
If you are open to jQuery and want a more open solution, I suggest you to take a look at the jQuery Form Plugin that can manage it all for you, with some extras that could be interesting.
My favourite tool for this is Uploadify. It includes real-time progress indicators, drag-and-drop, etc.
There are other, older solutions as well, including this one. That page has a simple demo that may provide a good example for how to do this on your own.
Honourable mention goes to Dave Walsh's facebook-lightbox, into which you might be able to put a file upload form. Worth a try if you like the look.
Try using something like AIM (http://www.webtoolkit.info/). And you should really get a little more experience on html, php and js.

php solution for parsing resulting html after ajax clicks

I'm currently using curl to login to a site and grab the html for one of the pages. My problem is that the page has some ajax links on it (click on the link results to html changes). How would I be able to make the clicks of the link and get the html of the final state using php? Seems like from researching this I need some sort of headless browser? Is there something like that in php I can use?
I'm not aware of any headless browsers that supports Javascript/AJAX that you can drive with PHP. If you want to drive a real browser with PHP, see http://seleniumhq.org/
Had this exact problem a few minutes ago. This works like a charm. Use .live() as the top answer here explains.
Reload javascript file after an AJAX request
Tested and works.

Execute Javascript code when a file upload completes without requiring page refresh

I have created a file-upload form and I want to output "filetransfer succeeded" in a <div> when the file transfer is done.
This is easilly done on a normal form using Jquery and Ajax but since this is a file upload it is not possible to use ajax.
So how do I upload a file and give feedback back to the user?
Consider looking at uploadify or swfupload.
I have personally used uploadify and you can do:
$('input[type=file]').MultiFile({
list: '#DIV to update'
});
jQuery actually has a pretty slick plugin called uploadify that'll let you do this. Alternately the iFrame solution Emil suggested will work as well without any outside libraries.
You can do it in an iframe.

Why not just using ajax for Page Requests to load the page content?

Many web pages load all of their content to change very little information.
Now I would like to know why shouldn't the developers just use ajax for the main page requests?
On my own webpage, I would like to develop the main requests on my webpage with just ajax but I don't know any specific cons with this approach.
Does anybody have an idea why someone shouldn't use ajax so much?
Search engines, crawlers/spiders, browsers with no javascript, screen readers and other consumers of the content will not be very happy with it.
You can provide tons of ajax behavior on top of you website if you already support standard server side navigation for the full content. Have a look at progressive enhancement (SO) and progressive enhancement (wiki).
The whole premise really is that with AJAX you don't need to reload the whole page to update a small percentage of that webpage. This saves bandwidth and is usually much quicker than reloading the whole page.
But if you are using AJAX to load the whole page this is in fact counterproductive. You have to write customised routines to deal with the callback of the AJAX data. Its a whole lot of extra work for little to no increase in performance.
General rule for where to use AJAX: If your updating >50% of your page, just reload, else use AJAX.
I'll give you one very good reason.
If you turn off javascript in the browser it won't work.
The biggest con are users who have JavaScript disabled. Your website simply won't work for them.
Aside from the answers already posted, using AJAX can have ugly side effects on browser control, such as the stop button not working.
One thing is that you want content to have a static url, you want people to be able to link to your pages, bookmark them, etc.
If everything is ajaxified, this could be tricky and/or tedious.
Well if you want to AJAX load new pages, such as the same way Gmail works, I suggest your links are normal A HREF links that point to a true full rendering page URL and alos use an onclick event that stop the attempt at normal link loading and make your AJAX calls. The problem here is you'll be doing almost double coding unless you architecture this all very well.
This way the normal non JS links load the full page, and the JS calls only load the new parts or page. This means spider indexing works again too.
Well, you can always add the onclick event unobtrusively using jquery and stop the normal URL handling.
Eg:
HTML
<a id="ajaxify-this" href="my-working-url">Click me to do AJAXy stuff if you have javascript</a>
then Javascript
$(document).ready(function() {
$("#ajaxify-this").click( function(e) {
updateContent(); // do something ajaxy with the page
return false; // stop the click from causing navigation
})
}
I use only JavaScript and EJS as template Engine for my own webside. One step closer to SOFEA/SOUI.
Search engines, crawlers/spiders, browsers with no javascript, screen readers dislike it, right. But I follow the mainstream ;)

Categories