I have recently came across a problem which I've never ever experienced!
I've basically created a form like this:
<form method="POST" enctype="multipart/form-data" action="">
<input type="file" name="file">
<input type="submit" name="submit">
</form>
After that I added a really simple PHP script, just for testing:
<?php
if (!empty($_POST['submit'])) {
echo 'OK';
} else {echo 'empty';}
?>
My settings in WAMP is that the file cannot be more than 2MB. Alright, so now if I upload an image or music or .exe or whatever file, it does shows the "OK" text. Even if it exceeds the file limit.
However when I upload a .zip file which exceeds the limit, it actually shows the "empty" message to me, so basically the form didn't submit, but the page reloaded.
So can anyone please tell me what is going on here? Because I don't really know what could be the issue here.
I don't know how, but I've found the answer.
The POST maximum size is actually more than 8MB. My zip files were much bigger and my music or exe files were not that big.
Thanks everyone for your help.
Related
I am able to upload other file types like .txt, .png, .apk using
<form action="index1.php" method="post" name = "mySuperForm"
enctype="multipart/form-data">
<input type="text" placeholder="Application Name" name="appname">
<input type="text" placeholder="Version Number" name="appversion">
Application File: <input style = "width:auto" type="file" name="file" id="file"><br>
</form>
But, when I try to upload a .ipa file, I can't grab the application name or version number on index1.php (the page I am posting to)using $_POST. However, if I upload a different file type, I can. It's as if nothing is getting posted if I try to upload an ipa file, like the html is failing on that line. I am using my localhost, wamp server. Any advice?
Without seeing your handling PHP, it's a bit difficult to diagnose, but here are a few potential items that may point you in the right direction:
Does the .IPA file exceed the *post_max_size* or *upload_max_filesize* as defined in your PHP configuration?
Try var_dump($_FILES); to see if your script is seeing the files there.
I think this is happening because the file is too big and the request is being truncated by the web server, so PHP would not be able to access any form fields because the request was not completed. How large is the ipa file? You might need to adjust your maximum post size. The default is usually 4 MB.
now first thing is I've seen everywhere over the net what to do in the case that what I'm trying to do doesn't work, I've tried all of the solutions and they don't work, I'm obviously missing something.
I'm uploading multiple files from a form field. This works perfectly and runs some code that resizes etc deletes tmp files blah blah.
The problem is if I don't want to upload any files the upload and image processing script still runs throwing a bunch of errors.
I've tried the following... plus a bunch more with some weird variations :P
if($_FILES['gallery']['name']!=""){ // if files then...
include_once("gallery_edit_script.php");
}
and
if (count($_FILES["gallery"]["name"] > 0)){ // if files count is more than 0 then...
include_once("gallery_edit_script.php");
}
Would the fact that the gallery_edit_script.php is an include have something to do with it?
I checked the file error with...
$_FILES["gallery"]["error"]
It showed no files were selected to upload which was exactly what I wanted.
Any ideas people?
Thanks for anyone who has a look at this.
Cheers
Added HTML but like I said upload is working fine, it's when I want to post the form and not include files to upload that I want it to skip the gallery script. This is on an edit page, so the user has submitted form, data added to db and files uploaded, then comes back and wants to edit data but not upload files.
HTML (simplified as there are heaps of fields etc)
<form action="inventory_edit_lease.php" enctype="multipart/form-data" name="myForm" id="myForm" method="post">
Gallery Photos <input class="input-file" type="file" name="gallery[]" id="gallery" multiple="multiple" />
<input class="button-edititem" type="submit" name="submit" id="button" value="" onclick="javascript:return validateMyForm();"/>
</form>
Sorry I didn't add HTML first time round, form works so didn't think I really needed it ;)
Few check lists...
Make sure you have named your <input type="file" /> as gallery:
<input type="file" />
Make sure the <form> tag has a method="post" and action="" to the correct URL.
Also, make sure your <form> tag has enctype="multipart/form-data" else you won't be able to upload files via that form!
We need to see the HTML Code of your file before we can suggest something. Make sure you have followed the above checklists and even then if it isn't working, post the code and let us know!
Without HTML form I'm just guessing:
for multiple file uploads with same name you must have the filed as
on server side you will receive them as $_FILES["gallery"]
$_FILES["gallery"] will be an array of elements, eg:
foreach($_FILES["gallery"] as $file){
var_export($file);
}
For those interested this is what worked :)
I got this from another thread if($_FILES['files']['name']!="") run if files, don't run if no files headache
if(!empty($_FILES['gallery']['tmp_name']))
{
include_once("gallery_edit_script.php");
}
else
{
header("Location: inventory_list_sales.php");
}
Funny thing is I tried this with another site I'm working on with almost identical code as I copied all the files and only edited small parts and it doesn't work lol
Thanks for everyone's help :)
Failed to upload file using HTML form:
after I click the submit botton, I could print out the $_FILES["file"]["name"] and $_FILES["file"]["type"] and ["size"] and ["tmp_name"] and
["error"] and etc.but I could not find the file in the tmp folder(it should be there by default)!I don't know why.
the html code goes like this:
<form action="manage.php?act=getback.questionOpt" target="fileUp" method="post" id="f1" enctype="multipart/form-data">
<p id="file_u">
<input type="file" name="file">
<iframe width="0px" height="0px" name="fileUp" style="display:none">
</iframe>
</p>
</form>
Uploaded files are deleted from the temp-directory unless they are moved or renamed!
There is a small note about that just above the third example on the PHP-Documentation at http://de2.php.net/manual/en/features.file-upload.post-method.php
Therefore you will not be able to see the file after the request is finished.
Simply renaming the file should do the trick.
How big is your file? If it is too big and exceeds your server limit, it won't upload. If your server has uploading disabled by default, you will need to turn it on in php.ini. This is how:
Open the php.ini file in your editor.
Search for the text string file_uploads. You will find something which says file_uploads = Off | On. If it says Off as the value, problem solved. Otherwise, it could be commented (check for semicolon at start of line). Otherwise:
Change the file permissions of your tmp folder.
Unless you show us the full code, there is nothing else I can do to help you.
so I am the webmaster/in charge collecting the files for a music video contest. The problem is I only know HTML, CSS, limited PHP, and some Actionscript 2. I need to be able to allow people to upload large files to my server (the videos they are submitting) but I am unable to find a way to do that. I was wondering if anyone had any suggestions of an upload system that work work for me. I have tired PHP's ftp_put but the files seem to be too large for it to handle. Thanks
I'm not sure if this will work for very large files, but I do some image uploading using a form and file inputs like so:
HTML
<form method="post" action="upload.php">
<input type="file" name="file" />
</form>
PHP
move_uploaded_file($_FILES['file']['tmp_name'], $server_path . $new_file_name);
You can also upload multiple files like so:
HTML
<form method="post" enctype="multipart/form-data" action="upload.php">
<input type="file" name="files[]" />
<input type="file" name="files[]" />
<input type="file" name="files[]" />
</form>
PHP
for ($i = 0; $i < count($_FILES['images']['error']); $i++)
{
move_uploaded_file($_FILES['file']['tmp_name'][$i], $server_path . $new_file_name[$i]);
}
I know for example youtube, as well as facebook have a process that uploads the files by parts ... but I don't know how it happens.
Another way would be to create an ftp account for each user and then they can use a program like filezila.
The other way, I think it would be an application in Java.
large files can also be handled by ftp_put, check your settings for upload_max_filesize, post_max_size, max_execution_time, max_input_time, and memory_limit in your php.ini file. These could all affect your file uploading abilities.
The problem with PHP uploading is that typically there's a file size limit and there's a server timeout limit as well, as in if the script is running for so long, it will time out. This becomes a problem in uploading larger files. If you can modify these settings yourself on your server then I suggest you try SWFUpload
I want to upload the files to this address: http://chusmix.com/Imagenes/grupos and I'm trying with this simple this code but it doesn't work:
<form enctype="multipart/form-data" method="post" action="http://chusmix.com/Imagenes/grupos">
Please specify a file:<br>
<input type="file" name="datafile" size="40">
</p>
<div>
<input type="submit" value="Send">
</div>
</form>
Oddly enough, the first result of a Google search yielded this rather helpful tutorial. Why not read it?
Read the PHP manual chapter "Handling file uploads":
http://php.net/manual/en/features.file-upload.php
The way you think uploads work is not the way they work. The form posts to the script you want to handle the request, not the location you want the uploads to be. When you upload a file to Apache, it places that file in the temporary directory of the computer (in Linux, that's /tmp by default).
Your script has to move the file from the temp directory to wherever you want it to be. The manual has plenty of code showing you how.
Make sure the form is loaded via
http://chusmix.com/Imagenes
The browsers wont you allow to upload to a unkown website (Same origin policy).
Edit your form
<form enctype="multipart/form-data" method="post" action="/grupos">