How to send file using http protocol without encode? - php

I want to send a png file to my apache server and export it using wireshark.
I tried a html form like this:
<form action="." enctype="multipart/form-data" method="post">
<p>files: <input type="file" name="datafile" size="40"></p>
<div>
<input type="submit" value="submit">
</div>
</form>
But i can't export my file as PNG. I think it happens because I use "multipart/form-data". I've heard that this encrypts the file. I'm not sure, what do you think I should try?

Related

how to upload SWF format in php?

My source code is to print upload SWF file tmp_name ?
<?php
echo json_encode($_FILES);
?>
<form method="POST" action="#" enctype="multipart/form-data" novalidate>
<input type="file" id="image" name="image" />
<input id="send" type="submit" name="data" value="Submit" />
</form>
But result i'm getting
{"image":{"name":"file.swf","type":"","tmp_name":"","error":1,"size":0}}
I have tried image uploading method no use on that !
{"image":{"name":"file.swf","type":"","tmp_name":"","error":1,"size":0}}
^^^^^^^^^
This error isn't specific to Flash at all. You'd run into the same issue with other formats as well.
Error 1 is UPLOAD_ERR_INI_SIZE. It means that the file you tried to upload was larger than your server's maximum upload size (upload_max_filesize), so the server didn't accept it.
Change this configuration value, or upload a smaller file.

PHP not process data from multipart/form-data forms

My website does no process data from forms with the enctype="multipart/form-data" set. However the 'php://input' gets the data even if the php manual says it shouldn't be available for the enctype. I think it might be some settings that is wrong but I have no idea which it might be.
Some code:
<?php
var_dump($_REQUEST);
echo file_get_contents("php://input");
?>
<form id="slideForm" action="" method="post" enctype="multipart/form-data">
<input type="text" name="test">
<input type="submit" name="submit" id="submit" value="ADD"/>
</form>
Update
I have been in contact with the support of the company that host the servers for my website and we have solved the problem. I'm not completly sure on what is the problem but it was somethin funky with their servers and php. I don't work on PHP 7.0 or PHP 5.6 but if I use their native (PHP 5.5) it works without problems.
I don't understand which type of data you want to POST. If it's just a test you should only have:
<?php
var_dump($_POST);
?>
<form id="slideForm" action="" method="post">
<input type="text" name="test">
<input type="submit" name="submit" id="submit" value="ADD"/>
</form>
If you want to POST a file you must have:
<?php
var_dump($_POST);
?>
<form id="slideForm" action="" method="post" enctype="multipart/form-data">
<input type="file" name="test">
<input type="submit" name="submit" id="submit" value="ADD"/>
</form>
Make sure you are able to POST data on your php server.
Check these php variables:
upload_max_filesize
upload_tmp_dir
file_uploads
In most cases you will not need to use this attribute at all. The default value (i.e. if you don't use this attribute at all) is "application/x-www-form-urlencoded", which is sufficient for almost any kind of form data. The one exception is if you want to do file uploads. In that case you should use "multipart/form-data".
Try the following code for echo "test" data.
<?php
var_dump($_REQUEST);
echo $_REQUEST['test'];
?>
<form id="slideForm" action="" method="post">
<input type="text" name="test">
<input type="submit" name="submit" id="submit" value="ADD"/>
</form>
I tried your code, and it is working as expected:
the $_REQUEST is populated properly and the php-input is empty.
Considering that your code looks fine, and it is working as expected on my server, i suggest you check your .htacces (or equivalent) for filter/rewrite modules, maybe even server config settings or even page encoding.
99% it's not the code itself.
<?php
// File data will display here
print_r($_FILES);
// OR you can write with condition
if($_FILES['test']){
print_r($_FILES);
}
?>
<form id="slideForm" action="" method="post" enctype="multipart/form-data">enter code here
<input type="file" name="test">
<input type="submit" name="submit" id="submit" value="ADD"/>
</form>
When you send the header Content-Type:multipart/form-data; PHP parses the data from request into $_POST and $_FILES and clears the input buffer. In order to read the input buffer you should remove that header.

Using reCAPTCHA and enctype="multipart/form-data" together

I have a file upload form on which I also want to use the Google reCAPTCHA.
If I have the following
<form method="post">
<input type="file" name="filename">
<div class="g-recaptcha" data-sitekey="***"></div>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
the I can use the reCAPTCHA, but cannot upload the file.
However, if I use:
<form method="post" enctype="multipart/form-data">
<input type="file" name="filename">
<div class="g-recaptcha" data-sitekey="***"></div>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
I can upload the file successfully, and use the reCAPTCHA provided that the file is a text file. I cannot get it to work if I try to upload a pdf file.
When uploading a text file, the $_POST contains the 'g-recaptcha-response', but when uploading a pdf, the $_POST does not contain the 'g-recaptcha-response'.
Can someone explain what is going wrong here?
EDIT
It seems like it's actually a filesize problem.
Files larger than ~200kb cannot be sent whatever their format.
I have upload_max_filesize = 2M in my php.ini file, so I'm not sure why 200kb is too large...
Any thoughts?
EDIT 2: More information
It looks like the $_FILE contains the error code 3: UPLOAD_ERR_PARTIAL.
I don't see why the file cannot be uploaded completely.
EDIT 3: Getting somewhere
I can now upload files. It seems like I need to put the reCAPTCHA before the file input.
<form method="post" enctype="multipart/form-data">
<div class="g-recaptcha" data-sitekey="***"></div>
<input type="file" name="filename">
<input id="submit" name="submit" type="submit" value="Submit">
</form>
Can anyone elaborate on why this might be the case?
Edit 4: Spoke too soon
Switching the order makes the g-recaptcha-response' appear in $_POST, but I am still getting the error code 3: UPLOAD_ERR_PARTIAL.
Edit 5
It looks like the file is being uploaded correctly, since I can see it in the header parameters (firefox debugger). It seems like php is just not filling in the $_FILE array properly...
I tried the same code on a different server and it worked fine.
Looks like the problem was that the server I set up has some sort of configuration issue. It actually has nothing to do with the interaction of reCAPTCHA and the file input + enctype.
I will update if I figure out what the configuration problem is.

Upload file without using web control

I am writing a fingerprint web application. I will read the fingerprint from user using ActiveX controls.
After that, I will get the image in the webpage. I found that the examples I found in the web requires users to click an upload image button and choose image from it.
Like the example below:
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
Some tells me that I need to use ftp to upload the file.
Can I have another choice? The best method is that I can use Http to upload.
You could send a data URI to the server using AJAX
Convert Data URI to File then append to FormData
However if you are using ActiveX, why not have the ActiveX send the data to the server from within the ActiveX?

Get remote file path location

I am working with PHP and would like to get a remote file path location so that I can read file contents.
I would like the user to direct to a particular file, which can be located anywhere in the computer, so that it can be processed by the script.
Thanks
You can offer a user the ability to locate a file on their local computer and submit it to you via a web form, like..
<form id="myForm" enctype="multipart/form-data" action="/formHandler.php" method="post" >
<label for="fileUpload">File to Upload:</label>
<input name="fileUpload" id="fileUpload" type="file" /><br />
<input name="submit" id="submit" type="submit" value="Upload Now"></form>
Then you can process it on your side with PHP, or whatever you have on the server end. Since PHP is one of your tags, you can learn more on how to access, and work with, on the server end from the PHP reference site:
http://www.php.net/manual/en/features.file-upload.post-method.php
I hope I understood your question correctly..

Categories