running a PHP file in background - php

I'm building an upload files form, it works fine but now i wanna add some extra features to it, for example,
When I upload the file the page im in sends me to the PHP page, then it echo's a message saying that its done and showing a preview of the image.
What I would like to do now is to stay in the same page as the file is being uploaded, then just get a message in the same page once the file is done uploading. So in other words not be sent to the PHP page instead that info (sent via form POST) can be sent in the background (maybe using XMLHttpRequest?)
Can somebody point me to the right direction to do something like that? i would greatly appreciate it.
Thanks!

You'll have to use javascript and APC_UPLOAD_PROGRESS to monitor the upload. Like this:
http://www.ibm.com/developerworks/library/os-php-v525/index.html
HTH

Related

How to show file uploading progress bar using html form and php code

I am using an HTML form to upload files
and PHP code to save the form file in the directory
and its working fine
But I need to show the progress bar using the browser status bar(shown in image file) or something similar
but now with the jquery etc.
let me know if there is any possible solution with pure HTML and PHP
don't mark my question down I have searched it everywhere
Thanks in advance

file upload using angularjs in php on button click

the upload using the angular frontend (whichever way this is handled) sends the file data to a script on the server such as a php script (which is my preferred method). Once the php script has run I want to return to the page from which the upload was made and give a message there..I dont want the php page to display. Will appreciate some guidance on how to achieve this. Ideally what code to add to the php script. but i want upload procedure on button click or ng-click not "onFileSelect"
You can use ng-file-upload directive, with many server side samples.
Follow here: https://github.com/danialfarid/ng-file-upload/wiki/PHP-Example

CodeIgniter upload files after preview

The flow of my multi-part form is basically Answer form -> Preview form -> Upload to database
Right now I upload my files in the Preview step since the POST data is fresh from the actual form. My problem is to access $_FILES once in the Upload to database function because var_dump($_FILES) returns array(0) {} once inside upload_to_database().
I thought of actually making hidden input[type=file] in the Preview step just so that my upload_to_database() will receive $_FILES, but this is not possible due to security reasons.
How do I solve this?
Edit
Sorry my post above was vague.
I actually want to upload once in the upload_to_database() function. I think it's bad practice to upload the user's files in the Preview stage unlike in Upload to database where they are sure of their answers.
The upload is currently in the Preview because right now it only works inside it. The $_FILES is empty once we go to upload_to_database().
How can I get a full and presistent $_FILES from Preview to upload_to_database()?
You could upload your files in the first step (when going to the preview form; like you are doing now), move them to a specific preview directory and move them to their final destination when you upload to the database.
I suppose you use something like sessions to keep track of the posted data so you could add the preview file path the same way.
Then you set up a simple cron job to delete all files older than xx hours in the preview directory every xx hours.
Edit: An alternative would be to do the preview completely client-side in javascript, like for example the preview of the questions and answers here on SO.
Isn't it possible to do something like this:
PREVIEW:
upload_to_database($_FILES['userfile']['tmp_name']);
DB:
function upload_to_database($file)
{
// work with file here
}
I mean to supply $_FILES as an argument to your upload_to_database function

PHP send data to parent window without using javascript

I am using FPDF to create a pdf document in an iFrame... During the pdf creation the script communicates and gets a lot of data from the server, and then I would like to display a progress bar.. That is why I have put the php generator in an iFrame.. then my plan was that the php script could send the looped data to the parent window..
e.g. every time a loop is made it says $count++;, then I know how many loops it has gone through, and I already know that it is going to limit the rows to the first 200 rows.. Then I would like to display the looped data in the parent widow like so: $count of §goal has been generated successfully!.. At the moment I am using jQuery, where I ask the php to echo some jQuery script every time a loop is made to display the results like so window.parent.count($count, $goal);.. Count in the parent winodw and it actually works well until the PDF has to be shown.. then I get an error message that tells me that the script is unable to display the PDF because the page already has outputted data..
Does anybody know how to make the PHP to send the data to the parent window, so I prevet the using of echo?
Sorry for my bad english.. if wished I can try to upload my script later for you to see...
I do it a bit differently...
I also wrote an application in which the PDF generator needs to fetch a rather large amount of data, so the generation takes a few seconds.
I use jQuery to fetch a php-page in the background. During this download, the screen turns gray and displays a classic "please wait"-circle. The only output that the php-file generates is an "OK" echo, together with a file link, when the generation has been completed. Instead of displaying the file inline, I save the PDF in a folder ($pdf->Output('filename.pdf','S')) and offer it as a download using the provided link and the jQuery-callback.
I hope you understand what I mean. Maybe this thought will help you a bit further.
EDIT: Don't know if this will work, but I just thought of it...
You could save the file and output the filename. Using jQuery, you could then refresh the contents of the iframe to fetch a page in which you display the already saved PDF inline...

how to make an interactive uploader like gmail and facebook have?

I want to make a interactive uploading option like Facebook and gmail have where they show the progress of the current file in uploading and then show the respective image or name of the file over there after the upload.
Right now, i'm using php and normal html for uploading where i send the file from one page to another where php handles it accordingly but i want a interactive one which show the progress also on the same page and then the name of the file after uploading without page refresh.
I knew, it can be done with ajax and css but i don't know how. All i want a interactive upload-er which uploads the file and then provide me the respective file name.
Gmail uses firefox file api, read more about it here https://developer.mozilla.org/en/Using_files_from_web_applications
Or check this live demo
http://robertnyman.com/html5/fileapi-upload/fileapi-upload.html
Hope this will help/solve ur problem ;) best luck

Categories