hellow my this is my form in jquery mobile i also turbed off the data-ajax and define the enctype but still i am not getting my file in my action page
<form id="form_id" action="action/cat-manag-add.php" enctype="multipart/form-data" data-ajax="false" method="post">
<label class="TSG-font" for="category_image">Category image:</label>
<input class="required" type="file" name="file" id="file" value="" >
<form>
this my action page getting all $_POST values but not getting the $_FILES
$title=$_POST['title'];
$description=$_POST['description'];
$file=$_FILES['file'];
kindly help me
Remove value="" in input type file.
And try var_dump($_FILES); check what is print in you action page
Related
I have this form:
<label for="pdffile">Upload</label>
<form class="form-horizontal" role="form" method="POST" name="upload" id="upload" enctype="multipart/form-data">
{{ csrf_field() }}
<input type="file" id="pdffile" style="display:none" form="upload"
</form>
It is supposed to be submitted with this jquery:
$('#pdffile').change(function() {
$('#upload').attr("action", "/upload").submit();
});
However when I check in PHP, nothing is uploaded:
dd($request)
Always gives me back null instead of the requested item.
Any help?
Your input does not have name
<input type="file" id="pdffile" style="display:none" form="upload"
change to
<input type="file" id="pdffile" style="display:none" name="upload"/>
and in your action you can use $_FILES to get upload file
<form method="post" enctype="multipart/form-data">
<h3>Add video</h3>
<div class="field_wrap">
<p>Name</p>
<input type="text" name="title"/>
</div>
<div class="field_wrap">
<p>Video</p>
<input name="video" type="file" />
</div>
<p><button>Add</button></p>
</form>
This is the form I use to upload a video file and a title, so when I DON'T upload a file the $_POST variable is filled with form data, but If I upload a file the $_POST variable is empty, why is that?
You are looking in the wrong spot, try looking in $_FILES not $_POST
<p><button>Add</button></p>
should be
<p><input type="submit" name="submit" value="Add"></p>
Using this all the post data is accessible as
$_POST and file data with $_FILES
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 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);
Is there a way to get the value of the name attribute in the form tag? I'm using PHP and don't see it in $_POST.
Is there a way to get the value of the name attribute in the form tag? I'm using PHP and don't see it in $_POST.
No, the form's name attribute is never set to sent to the server as part of the POST data.
The easiest way around this would be adding a hidden form element <input type="hidden"> containing the name.
<form name="myform" method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="frmname" value=""/>
</form>
<form name="wut">
<input type="hidden" name="name" value="wut"/>
</form>