how to upload SWF format in php? - 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.

Related

How to send file using http protocol without encode?

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?

file uploading in php not working for more than 20kb (i looked up all possible questions here)

<form action="uploads.php" enctype="multipart/form-data" method="post">
<?php
if(!empty($message)){
echo "<p>{$message}</p>";
}
?>
<input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
<label for="something">Please, upload your file</label>
<input type="file" name = "file_upload" id="something"/>
<input type="submit" name="submit" value="Upload" />
</form>
</body>
</html>
I changed post_max_size = 100M, max_file_size was already 64M. Problem is when I run the code and upload more than 20kb then first time it gives error no. 3 (partial upload problem) and then stop working. I have to restart php to do other thing. Please help..
In your php.ini file, change this variable upload_max_filesize to whatever max_uploaded_size you wish to have.
But remember, to keep your post_max_size greater than or equal to upload_max_filesize.
For more info, see this answer.
PHP change the maximum upload file size

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.

Filename maxlength

I have a form for file upload like this
<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>
Sometimes user upload files with 200 characters name.
Exist a way to limit filename maxlenghth?
The browser will expose the base file name to JavaScript so this is technically possible, although as #VisioN mentioned above, I can't think why you'd care; just rename the file on the server to something else. If you absolutely need to prevent it, then give your element an ID of uploader and then:
<script>
document.getElementById("uploader").onsubmit = function(){
return document.getElementById("file").value.length < 200;
};
</script>
Of course this will only work if JavaScript is enabled.
use the Code from Graham and check the filename length also with PHP
if(strlen($_POST['name']) > 200) { echo "filename to long"; exit; }
and you must added MAX_FILE_SIZE to you HTML-form otherwise PHP don't get the uploaded file
<input type="hidden" name="MAX_FILE_SIZE" value="MaximumFilesizeInBytes">
You should also validate it PHP side since someone could submit it directly to upload_file.php and bypass any HTML/JavaScript restrictions.

How to retrieve results from an external php file (file upload)

I am trying to post a file upload form to a php file that is located on another server but I do not know how to retrieve the results that are outputed using an iframe (i.e. basically a json object containing URL's being echoed by the upload.php). Is there any other way to retrieve the data?
code:
<form action="http://mydomain/upload.php" method="post" enctype="multipart/form-data" target="upload_target">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
Choose a file to upload: <input id="fileName" name="uploaded_file" type="file" />
<input type="submit" value="Upload"/>
<iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"> </iframe>
</form>
Thanks
Explode function just get the contents of the file you need with get filecontents then explode the part of HTML you need

Categories