PHP not sending any data with POST - php

I have this simple code:
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="titleDiv">
<h1>Image canvas</h1>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="previewDiv">
<img src="#" id="imgPreview">
</div>
<div class="buttonsDiv">
<button type="button" class="rotateButtons" id="rotateLeft">
<i class="fa fa-arrow-circle-left" aria-hidden="true"></i> Rotate left
</button>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="uploadDiv">
<form action="upload.php" method="POST" id="#uploadForm">
<!--<input type="file" name="img" accept="image/*" id="imgUpload">-->
<input type="number" name="number" value="0">
<input type="submit" value="Submit">
</form>
</div>
</div>
</div>
</div>
And on the upload.php file I have only 2 lines of code:
var_dump($_POST);
var_dump($_GET);
When I try to send this data over POST I get an output array(0) { } .
Though when I change the form method to method="GET" everything works normal and I receive the the data great on the upload.php.
I looked the php.ini file (I am using xampp as a local server) and the line ;enable_post_data_reading=Off is commented. Can someone help sort out this problem?

Check if you're actually using your webserver. What's the address on your navigation bar? It should be localhost without some strange ports. If it's pointing to 63342 that could be your problem.
edit: that could happen if you're using an IDE

Related

Hidden field not been submitted (Codeigniter)

I have made an application using codeigniter, and everything was working fine few day ago. But suddenly, yesterday, when I ran the application, I am getting error, when I am submitting data from the forms which contain enctype="multipart/form-data". Null data is received at the controller. When I remove enctype, than everything goes fine, but due to image upload, I have to keep enctype in some form tags.
<form action="<?= site_url('nasty_v2/dashboard/uploadPaid?key=').$this->my_func->scpro_encrypt("betul"); ?>" method="POST" role="form" enctype="multipart/form-data">
<div class="portlet box purple-sharp">
<div class="portlet-title">
<div class="caption">
<i class="fa fa-image"></i>Upload Payment Proof For
</div>
</div>
<div class="portlet-body flip-scroll" align="center">
<span style = "color : #b706d6;"><h2><strong>#<?= (120000+$orid); ?></strong></h2></span>
<div class="form-group">
<div class="fileinput fileinput-new" align="center" data-provides="fileinput">
<div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 200px; height: 150px; line-height: 150px;"></div>
<div>
<span class="btn red btn-outline btn-file">
<span class="fileinput-new"> Select image </span>
<span class="fileinput-exists"> Change </span>
<input type="hidden" value="" name="title"><input type="file" name="fileImg"> </span>
Remove
</div><div class="clearfix"> </div><button type="submit" class="btn btn-primary btn-circle"><i class="fa fa-upload"> Submit</i></button>
</div>
</div>
</div>
<input type="hidden" name="or_id" id="inputOr_id" class="form-control" value="<?= $or_id; ?>">
</div>
</form>
I checked the HTTP request using Telerik Fiddler 2, and the found that form is successfully submitting data in request, but that data is not reaching controller. What should be the issue?
It may cause by the file upload. Try setting followings
ini_set('max_file_uploads',1000);
ini_set('post_max_size','5000M');
ini_set('upload_max_filesize','5000M');
//or php.ini file

When trying to upload EPUB files the FILES and POST vars arrive empty

I have a working form that Inserts book entries to DB, it takes book title, isbn, book cover, etc.
I currently can upload the book cover and PDF version of the book without any issues, but the moment i try to upload a EPUB file instead of the PDF version, the FILES and POST arrive empty in the controller
-I have tried adding the mime types
'epub' => 'application/epub+zip',
//'epub' => array('application/octet-stream', 'application/epub+zip','application/smil+xml'),
The input works correctly because if i choose a PDF instead everything runs ok
// The form
<?php echo form_open_multipart(base_url().$this->uri->uri_string()); ?>
<div class="panel panel-default">
<div class="panel-heading"><h6 class="panel-title"><i class="icon-page-break"></i> </h6>
</div>
<div class="panel-body">
<h5>BOOK INFO</h5>
<div class="form-group">
<label>title:</label>
<input type="text" name="title" class="form-control" >
</div>
<div class="form-group">
<label>description:</label>
<textarea rows="5" cols="5" name="description" class="form-control"></textarea>
</div>
<div class="form-group">
<label>Cover:</label>
<input type="file" class="styled form-control" id="report-screenshot" name="userfile">
<span class="help-block">: gif, png, jpg</span>
</div>
<hr>
<h5>
FILES
</h5>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>EPUB:</label>
<input type="file" class="styled form-control" id="epub_file" name="epub">
<span class="help-block">: .EPUB</span>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>PDF:</label>
<input type="file" class="styled form-control" id="pdf_file" name="pdf">
<span class="help-block">: .PDF</span>
</div>
</div>
</div>
<hr>
<div class="form-actions text-right">
<input type="submit" value="Add" class="btn btn-primary">
</div>
</div>
</div>
<?php echo form_close() ?>
// In the controller
var_dump($_FILES); // array (size=0)
var_dump($_POST); // array (size=0)
It was the post limit.
The POST limit was set to 9mb, the PDF size of the book was 8mb, the image was 500kb, the EPUB was 9.2 mbs. Thats why everything uploaded correctly if i omitted the EPUB, but if i tried uploading the EPUB even on its own it got deleted. Unfortunately post_max_size_limit didnt throw any warnings.

how to activate two php scripts in html action tag at the same time?

I have two problems.
I want that when a user clicks on Vlado that the action will activate PamtiOdabranogZastupnika.php script in back-end and finally redirect the user to another web page.
I want that when you click on Pošalji that the action will activate two scripts, upis_podataka.php and e_mail.php.
Code:
<div class = "col-md-6 col-sm-6 col-xs-12">
<a data-toggle="pill" href="#forma_id" href="PamtiOdabranogZastupnika.php?vlado=true" ><img src="Vlado.jpg" class="img-rounded img-responsive" name="vlado"></a>
</div>
<form class="form-horizontal" role="form" action="upis_podataka.php" action="e_mail.php" method="POST">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-4">
<input type="submit" name="submit" value="Pošalji"/>
</div>
</div>
</form>

How can I use multiple input type file in one html form?

Recently I need to use multiple input type file in one form. But when I post the form its returning null. Like I have nothing on $_POST. I have also add the enctype="multipart/form-data". I am stacked for last 2 days. Googled for many times. But still didn't get any solution. Please help me to out of this.
<form enctype="multipart/form-data" action="/admin/process_post/savepost" method="POST">
<div class="uk-grid uk-grid-small" data-uk-grid-margin="">
<div class="uk-width-medium-7-10">
<div class="md-card">
<div class="md-card-content">
<h3 class="heading_a uk-margin-medium-bottom">Add New Canvas</h3>
<div class="uk-grid" data-uk-grid-margin>
<div class="uk-width-medium-1-1">
<div class="uk-form-row">
<label>Post Title</label>
<input type="text" name="post_title" id="post_title" class="md-input" />
</div>
<div class="uk-form-row">
<label>Post Description</label>
<textarea id="post_desc" name="post_desc" cols="30" rows="20"></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="uk-width-medium-3-10">
<div class="md-card">
<div class="md-card-content">
<div class="uk-form-row">
<p>
<input type="checkbox" name="post_status" id="post_status" checked data-md-icheck />
<label for="post_status" class="inline-label">Post Status</label>
</p>
</div>
</div>
</div>
<div class="md-card">
<div class="md-card-content">
<div class="uk-form-row">
<label for="post_attachment" class="inline-label">Post Featured Image</label>
<input type="file" id="post_attachment" name="post_attachment">
</div>
</div>
</div>
<div class="md-card">
<div class="md-card-content">
<div class="uk-form-row">
<label for="result_img" class="inline-label">Post result Image</label>
<input type="file" id="result_img" name="result_img" multiple="multiple">
</div>
</div>
</div>
<div class="md-card">
<div class="md-card-content">
<div class="uk-form-row">
<button type="submit" class="uk-form-file md-btn md-btn-primary">Save Post</button>
</div>
</div>
</div>
</div>
</div>
</form>
I know this is a silly situation for a developer when they face problem like this.
Files can be gotten through $_FILES
When doing multiple uploads at same name, name it as array appending [] at end of name example: ( name="images[]" )
If upload continues to appear as empty, and you said in comment that with one file it's doing right, try to change at php.ini post_max_size and upload_max_filesize to a larger amount. Also check max_file_uploads - the number of files allowed for uploads per single request.
Your problem should be your form action, try to put an "/" on the end of it and see if it works:
<form enctype="multipart/form-data" action="/admin/process_post/savepost/" method="POST">
You need to change your file input name to an array
<input type="file" id="result_img" name="result_img[]">
Also try adding multiple
<input type="file" id="result_img" name="result_img[]" multiple>
To check for files you must use $_FILES instead of $_POST

Handling PHP Request in same Page

I am trying to handle the Post request in the same page. But i am facing some issues when handling post parameters.I am always getting 'value as empty'.
Below is my code.
<body>
<?php include 'Header.html' ?>
<div class="container">
<div style="margin:10% 30% 0% 30%;">
<div class="panel panel-default">
<div class="panel-heading">
<h4 align="center" style="font-family: monospace;"><p>Upload External Device Report</p></h4>
</div>
<div class="panel-body">
<div class="container col-lg-12">
<form class="form-horizontal" action="UploadExternalReport.php" role="form" method='post' enctype="multipart/form-data">
<div class="input-group">
<input type="file" class="filestyle" data-buttonName="btn-primary" name="fileToUpload" accept=".xls ,.xlsx" required="required" >
</div>
<br/>
<button type="submit" class="btn btn-default">Upload</button>
</form>
</div>
</div>
</div>
</div>
</div>
<?php
// require_once '../PHPExcel/IOFactory.php';
if(isset($_POST["fileToUpload"]) && trim($_POST["fileToUpload"]) != ""){
echo $_POST['fileToUpload'];
}
else
{
echo'value is empty';
}?>
I tried !empty($_POST["fileToUpload"]) in if condition. But still its getting as 'value is empty'.
You are supposed to use the $_FILES array, not $_POST.
So make use of $_FILES['fileToUpload'].
http://php.net/manual/en/reserved.variables.files.php

Categories