I'm working a small management application and it requires us to to be able to upload images that are being trademarked, but in short I'm having problems retrieving the data to process it, after some debugging I've figure out that the form isn't passing any data to the $_FILES superglobal, and I can't figure out why.
This is the relevant form code:
<form
action="/contracts/entity/save_entity/trademark"
method="post"
enctype="multipart/form-data"
id="manage-entity-form"
>
<input
type="hidden"
id="MAX_FILE_SIZE"
name="MAX_FILE_SIZE"
value="102400000"
/>
<label for="file" class="">
<span class="ui-button-text">Image</span>
</label>
<input
type="file"
id="file"
class="ui-state-active"
name="data[Upload][]"
/>
</form>
The multipart/form-data encoding does not support multidimensional arrays - see this thread: How to upload files (multipart/form-data) with multidimensional POSTFIELDS using PHP and CURL?
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 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...)
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
I am trying to post a file upload form to a php file that is located on another server but I do not know how to retrieve the results that are outputed using an iframe (i.e. basically a json object containing URL's being echoed by the upload.php). Is there any other way to retrieve the data?
code:
<form action="http://mydomain/upload.php" method="post" enctype="multipart/form-data" target="upload_target">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
Choose a file to upload: <input id="fileName" name="uploaded_file" type="file" />
<input type="submit" value="Upload"/>
<iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"> </iframe>
</form>
Thanks
Explode function just get the contents of the file you need with get filecontents then explode the part of HTML you need
I keep getting an error:Notice: Undefined index: on line 35
line 35:
$handle = new Upload($_FILES['my_field']);
this is my input field
<input type="file" size="32" name="my_field" value="" />
I do not understand this error, thanks!!!
EDIT:
<form name="upload" id="upload" enctype="multipart/form-data" method="post" action="actions/upload.php" />
<p><input type="file" size="32" name="my_field" value="" /></p>
<p class="button"><input type="hidden" name="action" value="image" />
<br>
<input style="margin-left:224px;" type="submit" name="submit" value="upload" />
Update: The OP is doing an Ajax request - well that obviously can't work with a File upload.
Old answer:
I think I found it.
Look closely at this tag:
<form name="upload" id="upload" enctype="multipart/form-data" method="post"
action="actions/upload.php" />
the closing /> closes the form. Everything that comes afterwards, is not inside that form - it's inside a new one that the browser probably generates to deal with the broken markup. That new form is not enctype=multipart/form-data.
Did you use enctype="multipart/form-data" on the form element?
This seems to be the only reason that the the key my_field isn't set on $_FILES.
Edit: If your file is bigger than post_max_size, you also get an empty $_FILES array.
See also: Apache/PHP: $_FILES Array mysteriously empty
In order to upload WITH an ajax submission you can use an IFRAME with the upload part in there.
Send ajax form submission
Using javascript trigger submit() on the upload form in the IFRAME
Have the returning page in the iframe trigger a javascript complete response function in the main page
A bit complicated but would work. You would need some mechanism to tie them together, for instance if you are submiting info about the image, have step 1 return the id of the database row where that info is stored so that the IFRAME upload form can submit that id so it knows where to store the picture.