i have an issue with sending files form in magento CE 1.9.2.1. When i trying to attach files in php $_FILES array is empty but sometimes not. Please help me to find solution. Here is html form:
<form action="<?php echo $this->getUrl('quote/index/save', array('_secure'=>true)); ?>" id="get_a_quote" method="post" name="get_a_quote" enctype="multipart/form-data">
<div id="wizard">
<label for="attachment">Attachment</label>
<input type="file" name="attachment[]" multiple="multiple" />
<input id="submit" type="submit" name="save" value="Get A Quote" />
</div>
</form>
in IndexController my save action code is:
print_r($_FILES); die;// result Array() but sometimes Array(bla bla bla)
My server info is:
post_max_size = 8M
upload_max_filesize = 16М
Related
I know that this question has been asked many times before but I've searched through the already existing topics and I can't seem to find anyone with the exact same problem as me, so sorry in advance if it's already been covered.
My system is locally hosted and I have full read/write access to the tmp folder.
This is the relevant phpinfo from phpinfo():
file_uploads On
post_max_size 20M
upload_max_filesize 10M
memory_limit 128M
This is the form code:
<form enctype="multipart/form-data" class="form-group" action="./? action=create&id='.$id.'&next=1" method="post">
<label class="sr-only" for="thumbnail">Thumbnail image</label>
<input type="file" class="form-control" id="thumbnail" name="thumbnail" placeholder="Select the album thumbnail">
<br />
<input type="submit" value="Submit" class="btn btn-default btn-block" />
</form>
And when I print the var_dump of $_POST['thumbnail'] I get
null
Change From
<form enctype="multipart/form-data" class="form-group" action="./? action=create&id='.$id.'&next=1" method="post">
To
<form enctype="multipart/form-data" class="form-group" action="./? action=create&id=<?php echo $id;?>&next=1" method="post">
Then var_dump($_FILES['thumbnail']);
$_FILES is An associative array of items uploaded to the current script via the HTTP POST method.
In my index.php file , I got a code is trace the $_FILE, but seems like when uploaded a pic/jpeg/images file, the return result is 'array(0) { }'. Did I need use smarty's method to assign a input file's method?
var_dump($_FILES);
my photoupload.tpl
<form action="index.php?view=photoupload" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file">
<input class="btn_name" type="submit" name="submit" value="Submit">
</form>
No, you dont have to, heres a part of my current project where i work with smarty:
<form action="upload_contract.php" enctype="multipart/form-data" method="post">
...
<div class="row">
<div class="large-5 columns">
<label for="upload">Dateiupload:</label><span><input type="file" id="upload" name="upload"></span>
</div>
</div>
This one works fine without additional methods.
I have a simple HTML form containing a file input. When the form is submitted without a file, printing the $_POST array shows me all of the data submitted. When a file is submitted, however, $_POST doesn't print out any of the submitted data.
Can somebody tell me why? This is my code:
<?php
print_r($_POST);
?>
<form action="test.php" method="post" enctype="multipart/form-data">
<label for="myfile">Video File:</label>
<input type="file" name="myfile" />
<br /><br />
<label for="mytitle">Title:</label><br />
<input type="text" name="mytitle" size="55" maxlength="60" />
<br /><br />
<input type="submit" name="mysubmit" value="Submit Video for Approval" />
</form>
Your script seems fine. Please check your server configuration. Perhaps you exceed POST limits (set with post_max_size in php.ini)
You have to use $_FILES to access the uploaded files.
var_dump($_FILES); // Your uploaded files
var_dump($_POST); // Your entered data
I have this problem when I'm using PHP5/HTML on Apache-Tomcat6.
Here's an example for one of the forms I use in my site:
<form enctype="multipart/form-data" method="post" action="hello.php" >
<label>Title* :</label>
<input type="text" name="title" />
<label>Image:</label>
<input type="file" name="image" /><br />
<input type="submit" value="Add"/>
</form>
Whenever I add the 'enctype' attribute to any form; neither the $_FILES['image'] is returned nor the $_POST variables. As long as the 'enctype' is not there, everything (except for the file input of course) works as expected. Can any one guide me please?
You won't be able to post data with a method of get on your form.
In test.html:
<form enctype="multipart/form-data" method="post" action="hello.php" >
<label>Title* :</label>
<input type="text" name="title" />
<label>Image:</label>
<input type="file" name="image" /><br />
<input type="submit" value="Add"/>
</form>
In hello.php:
<?php
print_r($_POST);
print_r($_FILES);
Depending upon your server configuration, this will combine $_GET, $_POST, and $_COOKIE, but you'll still want to post with file inputs.
print_r($_REQUEST);
I have a form, like this
<form id="picuploadform" enctype="multipart/form-data" method="post" action="">
<div class="row">
<label for="fileToUpload">Select a File to Upload</label><br />
<input type="file" name="fileToUpload" id="fileToUpload" />
<input type="hidden" id = "picssn" name="picssn" value="qweweqwq">
</div>
<div class="row" style="width:150px;">
<input type="submit" value="Upload" />
</div>
</form>
Which when I click the submit button I have PHP on this page to process it just fine. $_FILES for receiving file and $_POST for reading picssn that came with the hidden input. But due to problem with Jquery mobile I can't use submit or .submit() now. So I want to use
$.post('myphpfile.php', {picssn:$('#picssn').value(), file: $('#fileToUpload').xxxxxxxxxxxxxxxxx });
instead. But I have no idea how to grab the file out of that form and send it this way. Is there some method that can replace xxxxxxxxxxxxxx ? Thanks!
On your form element, you need to disable the ajax submit, and then fix your other code.
Try this:
<form id="picuploadform" enctype="multipart/form-data" method="post" action="#" data-ajax="false">
<div class="row">
<label for="fileToUpload">Select a File to Upload</label><br />
<input type="file" name="fileToUpload" id="fileToUpload" />
<input type="hidden" id = "picssn" name="picssn" value="qweweqwq">
</div>
<div class="row" style="width:150px;">
<input type="submit" value="Upload" />
</div>
</form>
You cant upload directly via ajax. Check this perhaps:
http://blueimp.github.com/jQuery-File-Upload/ or uploadify.com