PHP post response takes too much time for images - php

i'm building a form page for create an ad, and this requires the addition of 1 or more images, so the user must compile the form, add the images, and send it with POST for go to the preview page before the ad is published.
The problem is the time taken by POST process for load the images, it's too much, is there a way for reduce this time? i know there is a method for resize the images with Canvas before the uploading, but what about the original file sent by the form with POST?

Sometimes i/o speed of virtual machines is not good. Sometimes the webservers allow only one connection from browser. You have to analyze what's going on on your server.
Check here.

Related

Webcam image stream for website implementation

Setting up a live image stream on a website, using images from a webcam. Trying to work out the implementation of it. The webcam takes a picture and requires a crop, resize and upload (not necessarily in that order), before it is displayed to the user, with a new image every minute. Currently I have a php script that does the cropping and resizing, while a webcam program automates the picture taking and uploading. However...
Uploading directly over the existing image causes an issue if the user reloads the page while the upload is taking place, resulting in a missing image.
Uploading with a different filename, then renaming it causes an issue if the user reloads the page during the renaming, resulting in a combination of both images.
Using a sequential filename system then gets tricky with the webpage requiring to know the new upcoming file every minute, along with a potential backlog of images.
Any suggestions are appreciated. Hopefully I'm missing something simple.
Thanks.
Just upload your image with different name, set the current image name somewhere, either in config file or MySQL, and after upload change it.

Images Gallery, Preloading vs AJAX

Hey I'm trying to make an image gallery but I am stuck at whether I should load all the images while the page loads or get ajax to request new images before they are displayed in the gallery?
The example below shows that I'm viewing the second image and have 2 hidden images loaded while image 5 is loading via ajax request. I thought if I keep two loaded images between the image being viewed and the image ajax is loading users should not have to watch an image load
Image Gallery (Viewing Single Image)
1 2 3 4 5
+-------+-------+-------+-------+-------+
| |Loaded | | * |Loading|
|Loaded | On |Loaded |Loaded | AJAX |
|Hidden | Show |Hidden |Hidden |Request|
+-------+-------+-------+-------+-------+
I havent used ajax off localhost so dont know what kind of performance it has compared to just loading the images with the page and hiding them.
You can generally rely on the browsers cache to load images quickly. A very dependable way that I've found to do this is with the following:
$("<img>").attr('src', imageSrc);
This creates an image element, doesn't append it to the DOM, but the browser will still download the image and cache it. With that, you can append either the image element you created or use a new image element with that image source and there shouldn't be a load delay.
I'm not sure what you mean by loading with ajax. Since an ajax request is not any different than any other request, there shouldn't be a performance difference between using "ajax" and "just loading" the images. There may be some overhead on the server if you are using a script to load the image in some way.
Ultimately, loading at HTML parse time, using javascript/jquery preloading or using ajax take the same time, especially if the image is large (if it wasn't, you wouldn't ask?).
The system has to open a connection, make a GET request for the file, and the file is transmitted over the network. If it is cached then it is not retransmitted. Network transfer is the bottleneck, and different load methods do not change that.
You'll influence your user's waiting times in two ways:
Reduce the size of your media, e.g. use thumbnails, be clever with compression, reuse large files so you exploit caching...
Time your image load carefully, which is what image preloading (with or without AJAX, it's the same thing) does. It's likely that it's impossible to know exactly when to start loading an image so the user won't wait. Loading three images ahead, as you propose, sounds fine to me. Users may, occasionally, wait, but more is overkill.
For a slide show, you could have an array to recall which images are unloaded, as a thumbnail, or fully loaded, which will ensure you don't make unnecessary repeat requests.
I've not really given you a magic bullet... There isn't one, but I hope this helps.
I have already have this situation in which i have also taken both sample find the solution
Basically for basic image [thumbnail image] loading you can use lazy load for the page
and for the loading the large or main image you can load the thumbnail image into that and after you can write the code for loading the large image into it.
$('#GalleryImage img.mainImage').load(function() {
$(this).attr('src',$(this).attr('src').replace('thumb','large'));
});
May this will help you

Upload multiple files while navigating other pages - howto?

I'm creating a website and I'd like to allow users to upload multiple files while they navigate the website.
When the upload completes, it would be nice to have a Javascipt event triggered, to allow the user to specify additional info related to the uploaded files (eg. photo location, tags, etc)
anyway, the required features are:
multiple files allowed for a single upload operation
display an optional progress indicator (at least in the "x of y files uploaded" fashion)
doing it without tying the users to a single page
How can I implement these features?
Any suggestion is greatly appreciated!
Edit
In the event of using a popup window to handle uploads, how can I:
inform the user (on the "master" page) that the upload has completed, or that there have been errors?
(more important) pass the $_FILES array to the popup window? I'd like the user to be able to click "upload" on the main window, or anyway to make the upload start from the main window (eg dragging and dropping files on the main window).
Since navigating the site will switch pages and it's unlikely that there's a full ajax navigation on your site, maybe it could help to somehow upload the files in a second popup window. Not sure how (if) it could be implemented, though, but since you need to upload multiple files at a time I'm afraid you're bound to use flash.
EDIT
So the solution could look like this:
When a user clicks a "select files" button you pop out a new window where he'll be able to actually select files (via flash if multifile upload is necessary). And to notify of upload progress use postMessage. Though postMessage isn't going to work in IE in this case, but probably you could somehow send the message to the server and from the server back to the page.
Another crazy idea is not to use a popup window, but let the user select the files on the page she was first, but once the user selects the files make all the links on the page target=_blank to make any subsequent navigation happen in another tab. I know it's hacky and not exactly user-friendly, but probably could help.
In any case I would inform the user beforehand that a new window will appear in both scenarios.
EDIT2
And an even crazier idea. When the user selects the files and clicks a link create an iframe which will cover the whole page and hide the original page beneath it and make the links open in the iframe. But it looks even more hackish and it seems you'll have much trouble with it.

Blog with heavy load of pictures-Speed up page

i'm building a travel blog (Php) where I might be loading dozens of pictures (size 500x375 weight 150-200kb) so that the page weights more than 4-5Mb.
Which is the way to go apart from caching/gzip to decrease waiting time and make a better user experience?
I'm on a shared server as my budget is very low
thanks
Some options:
split up the images across multiple pages
use a 'lazy load' script that will only request images as they come into the viewport
use AJAX to request images as needed via a user action
leverage external hosting of the images (flickr, etc) to split the server requests amongst different servers.
If you're displaying dozens of images on one page, I would consider just showing small images / thumbnails that get enlarged when the visitor clicks on them.
There are some points that solve this issue
1) Show few images and below that show more link or icon
2) After clicking on that give ajax call and show other images
3) Also you use 'jQuery lazy loading plugin'(it's very easy to integrate..click here to see integration step)

A good "loading" function in combination with a picture upload utility (PHP + JS)

I have a classifieds website, and when posting a new ad, users may chose to upload pictures.
Currently, the form on the page submits to itself whenever a file is chosen, and then PHP uploads the actual file, which is then lastly displayed to the user.
I use javascript to set some hidden-inputs on the page, and then submit the form to itself:
if (action!='remove'){
document.getElementById("pic_nr").value=nr;
document.getElementById("total_pics").value=nr;
document.getElementById("pic_action").value='upload';
var form = document.forms['ad'];
form.action='new_ad.php';
form.submit();
}
Then in PHP, it processes and uploads the image (which takes some time) and after its done the image is displayed in the same form.
Now I need to have a progress bar of some kind, which shows the user that the server is actually DOING something.
Because uploading a standard 2,5MB file from a digital-camera takes some time (around 10s), and usually the user doesn't understand that "something is happening" in the background.
Is there any standard reliable, cross-browser solution to add a loading bar with either JS or PHP, or even maybe both combined?
Any tips and ideas are appreciated.
Thanks
This site seems to have a pretty comprehensive list of tutorials with various approaches. JQuery to me would seem to be the best option to go with as it usually is pretty reliable between browsers and platforms.
you could POST the form using AJAX and on firing the form POST load a "loading" spinner on the page until you get a postback with a status from the server.
I'm adding a link to a sample HTML5 script that does it with drag-n-drop...
http://craigslist.fatherstorm.com/dragndrop.php

Categories