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.
Related
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М
I have such an upload form:
<form id="ajax-contact-form" action="" method="post" enctype="multipart/form-data" name="form1">
<INPUT type="text" name="name" value="Material Name:" onBlur="if(this.value=='') this.value='Material Name:'"
onFocus="if(this.value =='Material Name:' ) this.value=''">
<div class="clear"></div>
Choose a file to upload<br />
<!--APC hidden field-->
<input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $up_id; ?>"/>
<div class="clear"></div>
<!---->
<input name="file" type="file" id="file" />
<div class="clear"></div>
<!--Include the iframe-->
<br />
<iframe id="upload_frame" name="upload_frame" frameborder="0" border="0" src="" scrolling="no" scrollbar="no" > </iframe>
<br />
<!---->
<INPUT class="submit" type="submit" name="submit" value="submit">
<div class="clear"></div>
</form>
I'm using php, and I have to fetch directory name of the uploaded file to use in azure.
How can I manage this?
Thanks.
If you are not using a framework, you could use the global $_FILES when processing the form.
That will be an array of each of the files you form submitted, using the "name" of the input as key (which in your sample form is missing).
Inside that key, you'll find "name", "type", "tmp_name", "error" and "size".
tmp_name will have the absolute path to the temporary file stored on your server. The rest is self explanatory.
Now, if you are using a framework to process the form, most frameworks have an easier and error-proof way of fetching files from the request.
Update
$_FILES['file']['tmp_name'] will have the absolute path on your server to the uploaded file.
With that, you can do file_get_contents() or whatever you like.
$_FILES['file']['name'] wil have the name of the file, in case you need to persist it somewhere.
If you are using a debugger such as xdebug, you could set a breakpoint, and look at the global yourself to get a better idea.
If not, you can always do a var_dump($_FILES); in order to view the structure and get a sense of what is happening on the server.
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 basic username & password form which also allows you to upload an image with it. There's a create button, which takes the user to uploader.php which both uploads the image and inputs the username & password into the database.
Within the form tag:
< form enctype="multipart/form-data" method="POST" action="uploader.php?uploader=avatar&username=< ?php echo $_POST['username']; ?>" >
The problem:
The username won't post, nor any other posts for that matter. All fields are inside the form. I have checked PHP file upload form cannot submit a POST variable? and within php.ini post_max_size = 8M, and upload_max_filesize = 2M
Use <input type="hidden"/> to post username and other info.
<form enctype="multipart/form-data" method="POST" action="uploader.php">
<input type="hidden" name="uploader" value="avatar"/>
<input type="hidden" name="username" value="<?php echo $_POST['username']; ?>" />
...
</form>
Sample.php
<form enctype="multipart/form-data" method="POST" action="uploader.php">
<br/>Username : <input type="text" name="username"/>
<br/>Password : <input type="password" name="password"/>
<input type="hidden" name="uploader" value="avatar"/>
<br/>File : <input type="file" name="file"/>
<br/><input type="submit"/>
</form>
uploader.php
<?php
print_r($_POST) // debug $_POST
print_r($_FILES) // file
//OR
echo $_POST["username"];
$file=$_FILES["file"];
print_r(file);
?>
It sounds like you want to submit the username and password and upload a file all in the one submit.
If this is what you want, you need something like the following:
<form enctype="multipart/form-data" method="POST" action="uploader.php">
<input type="text" name="username" value="" />
<input type="password" name="password" value="" />
<input type="file" name="uploaded" />
...
</form>
The username and password will be available in $_POST[] and the file will be present in $_FILES[].
I had this problem when the files I was attempting to upload were larger than the max filesize PHP was accepting. Look at:
ini_get('post_max_size')
and
ini_get('upload_max_filesize')
to see if your file is too big. My solution was to use empty($_POST) to determine if the file was too big (or some other posting problem occurred) and throw an Exception.
Oddly I had the same issue, until I add the enctype="multipart/form-data" attribute.. After that, all worked
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