The PHP documentation doesn't explain what happens when there are two files being uploaded at the same time within the same session (two uploads running in two tabs of a browser).
Is there any way to track the progress of both uploads?
Is the first upload status lost when the second one starts?
Thanks!
Yes, it is possible to monitor the status on two different uploads in different tabs using PHP's Session Upload Progress feature. All you need to do is make the upload progress name different on both forms by changing the value="" parameter of the hidden upload progress name field.
For example, the upload form for tab 1 could look as follows:
<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="<?php echo ini_get("session.upload_progress.name"); ?>" value="tab1">
<!-- notice the value="tab1" above -->
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<input type="file" name="myUploadName" />
<input type="submit" />
</form>
Then, the upload form for tab 2 could look as follows:
<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="<?php echo ini_get("session.upload_progress.name"); ?>" value="tab2">
<!-- notice the value="tab2" above -->
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<input type="file" name="myUploadName" />
<input type="submit" />
</form>
Now that you have created two different upload progress sessions, you can get the progress data on the PHP side as follows:
$_SESSION['upload_progress_tab1'] // Progress data for tab 1
$_SESSION['upload_progress_tab2'] // Progress data for tab 2
This example could work for you:
http://www.johnboy.com/php-upload-progress-bar/
You need some client (JS) code and a bit of PHP
Related
First off, I have no experience with PHP. I'm setting up a form on a site that is hosted on Dotster using their link. This works to send an email with all of the info, but the file that is selected for upload disappears. Does not end up on the server, does not attach to the email. Are there any ways to determine or control where the file goes using their script?
<form method="post" action="https://www1.dotster.com/scripts/formemail.html" enctype="multipart/form-data">
<input type="hidden" name="my_email" value="flyboyjr#gmail.com">
<input type="hidden" name="subject" value="Nomination Form">
<h1>Nominee Information</h1>
<label for="photo">Please upload a photo of the nominee in uniform or sports attire appropriate with
their
nomination. Please make sure it includes a clear view of their face.</label><br><br>
<input type="file" id="photo" name="photo" required>
I have an html form and 2 php files, all of which work well. In the form I created a preview button that references a php file that shows the uploaded cvs in an html table as a preview. The submit button inserts it into a database.
I would like to have the form contain one button that goes to the preview page and once the info is confirmed, there would be another button that references the submitted file, but I can't seem to get that to work.
Due to the environment I'm trying to get this to work without javascript or ajax if possible, as another user gave me a javascript option.
Here is the html form:
<form method="post" action="confirm.php" enctype="multipart/form-data">
<label>Upload File</label>
<input type="file" name="file">
<input type="submit" name="submit" value="Confirm" >
</form>
<form method="post" action="upload.php" enctype="multipart/form-data">
<label>Upload File</label>
<input type="file" name="file">
<input type="submit" name="submit" value="Submit">
</form>
Each Php file corresponds as well:
if(isset($_POST['submit']))
Is there any way to go from upload to preview to submit and keep reference to $file?
I have the following form that allows uploading a file:
<form id="form1" name="form1" method="post" action="page1.php" enctype="multipart/form-data">>
CSV list: <input type="file" name="file" id="file">
<input type="submit">
</form>
When I go to my action/submit page I can retrieve the file and the temp location of the file, but I need to send it through again to a new page, so I do the following:
<form method="post" action="page2.php" name="details" >
<input type="hidden" id="type" name="type" value="1">
<input type="hidden" id="filename" name="filename" value="<? echo $_FILES["file"]["tmp_name"]; ?>">
<input type="submit" value="Insert Into Database">
</form>
This doesn't work because the temp file is already gone.... how can I pass the file through?
I think you want to rethink how you are getting this data. If it was me, I would want to have the first form upload the file to a temporary directory and pass the path to the file through a $_REQUEST. Then use a hidden input field pass the file path name through PHP and if they confirm their selection on the second form, do whatever you want with the file using the file's path. This means you don't have to upload two files(not efficient) and you can pass the data onto the second form.
I have a very basic PHP multiple file upload form:
<form action="file.upload.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?php echo $_REQUEST['id']; ?>" />
<input type="hidden" name="bypass" value="1" />
<input multiple type="file" name="file[]" id="file">
<input type="submit" name="submit" value="Submit">
</form>
Everything works fine for a few files, but when I upload too many large files, the hidden variables are no longer posted to PHP (!)
I am not sure what is causing the from variables to be ignored by PHP (?)
(I've checked with fiddler and the form indeed sends the right data from clientside... i.e., form fields bypass and id are both properly populated on clientside...)
I have a form such that a list of questions with inputs is followed by an invitation to upload files if they have them.
I have avoided nesting forms by popping up the form containing the upload. The difficulty is that if they press submit on the Uploader form, it will process the upload on the destination page, and likewise if they hit submit on the rest of the form, the uploads are not submitted.
How can I do both at once?
My code:
<form id="questions" action="page2.php" method="POST">
Question 1 <input name="q1"/>
Question 2 <input name="q2" />
Have any files to add? <button id="upload-button">Upload</button>
<input type="submit" value="Submit Answers" />
</form>
<div class="hidden">
<form id="fileupload" enctype="multipart/form-data" action="uploader.php" method="POST">
<input id="fileupload" type="file" name="files[]" multiple>
<input type="submit" value="Upload Files" />
</form>
</div>
jQuery will pop up the hidden div if someone presses the button to add files.
I don't have a problem with them being posted to the same place, but I tried using javascript to use the click event for each button to submit both forms and it did not work.
(Reading stack overflow later explained that only the last submission gets processed in this way)
Any ideas? Thanks
Very simply, structure your HTML like this, and process the logic from both page2.php and uploader.php in one shot (i.e. include the file-upload logic in page2.php). If you show us the contents of both of those files, I can show you how to combine them.
Also added labels with links to the associated inputs, and swapped the submit input for a button element.
<form id="questions" enctype="multipart/form-data" action="page2.php" method="POST">
<label for="q1">Question 1</label>
<input id="q1" name="q1" type="text" />
<label for="q2">Question 2</label>
<input id="q2" name="q2" type="text" />
<label for="fileupload">Upload a File<label>
<input id="fileupload" type="file" name="files[]" multiple />
<button type="submit">Submit</button>
</div>