Failed multi upload when images size goes height - php

I'm using php to upload my pics but when my selected images size goes to height
my upload failed. On the page no error show for this happend This is like refresh page but my selected images size is lower than 3 MG it Works Well
whats my problems.
PLEASE HELP ME.
$output_dir = "../PostImage/";
if(isset($_FILES["myfile"]))
{
$ret = array();
$error =$_FILES["myfile"]["error"];
{
if(!is_array($_FILES["myfile"]['name'])) //single file
{
$RandomNum = time();
$ImagePostName=jdate("HisYmd",$timestamp)."".$RandomNum."".convert_filename_to_md5($_POST['title'])."".$_FILES["myfile"]["name"];
move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir. $ImagePostName);
}
else
{
$fileCount = count($_FILES["myfile"]['name']);
for($i=0; $i < $fileCount; $i++)
{
$RandomNum = time();
$ImagePostName=jdate("HisYmd",$timestamp)."".$RandomNum."".convert_filename_to_md5($_POST['title'])."".$_FILES["myfile"]["name"][$i];
move_uploaded_file($_FILES["myfile"]["tmp_name"][$i],$output_dir.$ImagePostName );
}
}
}
}
<form name="form1" method="post" action="index.php" enctype="multipart/form-data">
<input class="form-control input-lg m-bot15" name="myfile[]" id="myfile" multiple="multiple" type="file"/>
<input type="submit" value="upload" placeholder=""/>
</form>

You need to set the value of upload_max_filesize and post_max_size in your php.ini :
; Maximum allowed size for uploaded files.
upload_max_filesize = 40M
; Must be greater than or equal to upload_max_filesize
post_max_size = 40M
After modifying php.ini file(s), you need to restart your HTTP server to use new configuration.
If you can't change your php.ini, you're out of luck. You cannot change these values at run-time; uploads of file larger than the value specified in php.ini will have failed by the time execution reaches your call to ini_set.

If you can't change your php.ini, you're out of luck. You cannot change these values at run-time; uploads of file larger than the value specified in php.ini will have failed by the time execution reaches your call to ini_set.

Related

I cannot upload files > 100K

I am not able to upload files larger than 100KB. Uploading multiple smaller files is OK. This is LAMP running on Fedora 27.
Here are the pertinent code snippets. The return value is "2", which I believe means that the file is too big. I've already set and adjusted the usual suspects in php.ini. I am not getting to $mail->AddAttachment so I don't expect that it is a phpmailer issue.
Front End Code :
<form method="post" enctype="multipart/form-data"\>
<input name="file_arr[]" id='userfiles' type="file" multiple="multiple"/ >
<input type='submit' name='submit' id='submit' value='Send' />
Back End Code :
$mail = new PHPMailer;
.
foreach ($_FILES["file_arr"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["file_arr"]["tmp_name"][$key];
$fname = $_FILES["file_arr"]["name"][$key];
$mail->AddAttachment($tmp_name, $fname);
$fcnt++;
} else {
return($error);
}
}
Adjust php.ini
You need to check php.ini to see what your max file upload size is set to. You can adjust memory_limit, upload_max_filesize, post_max_size variables accordingly.
Get php.ini Location
To find your php.ini, run phpinfo() and echo the results: echo phpinfo();
You may or may not need to echo phpinfo().

Extra Large size file upload Doesn't working using PHP/HTML

I don't want to restrict user to upload large file. User can upload any file size. When i tried file size of 22 MB, It worked. But When I tried 200MB file, it seems it does not entered in if block and return me the output of else block after taking all the time in the world to upload file.
My work on this is mention below. Am I missing something?
HTML:
<form method="post" enctype="multipart/form-data" class="form-horizontal" role="form">
<label for="document">Upload your Document</label>
<input type="file" id="document" name="document">
<label for="doc_cat">Document Category:</label>
<select name="doc_cat" id="doc_cat" class="form-control" required>
<option value="">--Select a Category--</option>
<option value="1">Sales</option>
<option value="2">Technical</option>
<option value="3">Pricing</option>
<option value="4">Policies</option>
<option value="5">Other</option>
</select>
<button type="button" class="btn btn-primary" id="upload" name="upload">Upload</button>
</form>
JQUERY/AJAX:
<script type="text/javascript">
$(document).ready(function () {
$('#upload').click(function () {
var formData = new FormData($('form')[0]);
var that = this;
$.ajax({
url: 'upload-document-proccess.php', //Server script to process data
type: 'POST',
data: formData,
async: false,
beforeSend: function() {
$("#loading-image").show();
},
success: function (msg) {
$("#loading-image").hide();
$("#display-return-msg").html(msg);
$("#display-return-msg").fadeIn("slow").delay(5000).fadeOut("slow");
},
cache: false,
contentType: false,
processData: false
});
$('form')[0].reset();
return false;
});
});
</script>
upload-document-proccess.php:
if(isset($_POST) && $_FILES['document']['size'] > 0)
{
$category_id = $_POST['doc_cat'];
$doc_desc = htmlspecialchars($_POST['doc_desc'],ENT_QUOTES);
switch ($category_id) {
case 1:
$category="Sales";
break;
case 2:
$category="Technical";
break;
case 3:
$category="Pricing";
break;
case 4:
$category="Policies";
break;
case 5:
$category="Other";
break;
default:
# code...
break;
}
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["document"]["name"]);
$fileName = $_FILES['document']['name'];
$tmpName = $_FILES['document']['tmp_name'];
$fileSize = $_FILES['document']['size'];
$fileType = $_FILES['document']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
if (move_uploaded_file($_FILES["document"]["tmp_name"], $target_file)) {
$msg = "The file ". basename( $_FILES["document"]["name"]). " has been uploaded to ".$category." Category";
} else {
echo "Sorry, there was an error uploading your file.";
}
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
try {
$sql = "INSERT INTO document (doc_name, doc_type, doc_size, user_id, doc_category_id, doc_date, doc_desc)
VALUES ('$fileName', '$fileType', '$fileSize', '$user_id', '$category_id', now(), '$doc_desc')";
// use exec() because no results are returned
$conn->exec($sql);
?><script type="text/javascript">
var msg = '<?php echo $msg; ?>';
$(document).ready(function(){
$("#display-return-msg").html(msg);
$("#display-return-msg").fadeIn("slow").delay(5000).fadeOut("slow");
});
</script>
<?php
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
//echo "<br>File $fileName uploaded<br>";
}else{
echo "Please select File to upload.";
}
?>
In '#display-return-msg' id, It gives me "Please select File to upload" when i uploaded 200MB file. When i uploaded 22 MB file, I got value of 'msg' variable which is correct. Please suggest me What do i do?
there are a lot of settings that could restrict the filesize of your upload. here is an example based on an XAMPP installation on windows. but it should be quite similar on linux.
found at http://mewbies.com/how_to_install_setup_apache_xampp.htm:
TO CHANGE SIZE OF FILES ALLOWED TO UPLOAD:
To allow large file uploads you must change the settings on your PHP & Apache conf files, we'll use
600MB file size as the example, change it to your own needs:
Edit this file: D:\xampp\php\php.ini
Search for: upload_max_filesize
Change
to:
upload_max_filesize = 600M
Search for: post_max_size
Has this:
post_max_size = 8M
Change to (it must be larger than upload_max_filesize):
post_max_size = 700M
Search for: memory_limit
Has this: memory_limit = 128M
Change to, if you don't want any limit:
memory_limit = -1
Or change to (it must be larger than post_max_size):
memory_limit = 800M
Search for: max_execution_time
Has this: max_execution_time = 30
Change to for example:
max_execution_time = 9600
Search for (just below max_execution_time): max_input_time = 60
Has this: max_input_time = 60
Change to: max_input_time =3600
Done, save the changes.
Edit this file: D:\xampp\apache\conf\extra\httpd-default.conf
Search for: LimitRequestBody
If your conf does not have this line; add it
Has this: LimitRequestBody 102400
Change to:
LimitRequestBody 600000000
you set it to 0, meaning unlimited up to 2147483647 bytes (2GB)
Restart your web server.
To upload large files to web server, need to modify some settings (using .htaccess) in the php. Two php configuration options, the maximum upload size: upload_max_filesize and post_max_size. Both can be set to, say, "200M" for 200 megabyte file sizes.
you can test like at the very first line use this line
echo phpinfo();exit;
and find and check 'max_file_uploads' if it does have less than your requirement increase it by writing at the very first of page
ini_set('max_file_uploads', 'as per your need size')
You need to increase upload limit in php.ini file
EDITED: You should ask host to allow you owerwrite php ini configuration for upload limit, if they do this for you will be able to do this, if they can't or don't want you wont be able to to this.
After they enable this you can:
1.create local copy of php.ini in folder where is script which performs upload
2.you can do it in code, example for turning of erro reporting:
error_reporting(-1);
3.you can set this in cpanel for this account if is possible/enabled.

PHP file upload error tmp_name is empty

I have this problem on my file upload. I try to upload my PDF file while checking on validation the TMP_NAME is empty and when I check on $_FILES['document_attach']['error'] the value is 1 so meaning there's an error.
But when I try to upload other PDF file it's successfully uploaded. Why is other PDF file not?
HTML
<form action="actions/upload_internal_audit.php" method="post" enctype="multipart/form-data">
<label>Title</label>
<span><input type="text" name="title" class="form-control" placeholder="Document Title"></span>
<label>File</label>
<span><input type="file" name="document_attach"></span><br>
<span><input type="submit" name="submit" value="Upload" class="btn btn-primary"></span>
</form>
PHP
if(isset($_POST['submit'])){
$title = $_POST['title'];
$filename = $_FILES['document_attach']['name'];
$target_dir = "../eqms_files/";
$maxSize = 5000000;
if(!empty($title)){
if(is_uploaded_file($_FILES['document_attach']['tmp_name'])){
if ($_FILES['document_attach']['size'] > $maxSize) {
echo "File must be: ' . $maxSize . '";
} else {
$result = move_uploaded_file($_FILES['document_attach']['tmp_name'], $target_dir . $filename);
mysqli_query($con, "INSERT into internal_audit (id, title, file) VALUES ('', '".$title."', '".$filename."')");
echo "Successfully Uploaded";
}
}else
echo "Error Uploading try again later";
}else
echo "Document Title is empty";
}
I just check the max size in phpinfo();
Then check if php.ini is loaded
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
Then Change the upload_max_filesize=2M to 8M
; Maximum allowed size for uploaded files.
upload_max_filesize = 8M
; Must be greater than or equal to upload_max_filesize
post_max_size = 8M
Finally reset your Apache Server to apply the changes
service apache2 restart
var_dump($_FILES['file_flag']['tmp_name']); // file_flag file key
will return empty string
array (size=1)
'course_video' =>
array (size=5)
'name' => string 'fasdfasdfasdfsd.mp4' (length=19)
'type' => string '' (length=0)
'tmp_name' => string '' (length=0) <===== *** this point
'error' => int 1
'size' => int 0
This happen because WAMP server not accepting this much size to uploaded on server.
to avoid this we need to change php.ini file.
upload_max_filesize=100M (as per your need)
post_max_size = 100M (as per your need)
finally restart server
another option is to add a separate config file with upload limits.
i created uploads.ini:
memory_limit = 64M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 60
and placed it in conf.d directory
in my case using Docker: /usr/local/etc/php/conf.d/uploads.ini
that way i could keep my production php.ini and add this just for uploads control

PHP uploading a file not working

The code below is to upload files to a local folder. Once I select a file from the Dialog Box, it should display "OK" to confirm selection of file. But the code below is not working as required.
<?php
if(isset($_FILES['file']['name']))
$name = $_FILES['file']['name'];
if(isset($_FILES['file']['tmp_name']))
$tmp_name = $_FILES['file']['tmp_name'];
if(isset($name))
{
if(!empty($name))
echo 'OK';
else
echo 'Please chose a file';
}
?>
<form action="up.php" method="POST" encrypt="multipart/form-data">
<input type="file" name="file"><br><br>
<input type="submit" value="Submit">
</form>
First try:
var_dump($_FILES);
If you are not seeing anything in there on post, then you may need to set the following in your php.ini file:
file_uploads = On;
You may also need to change the allowed file sizes in the php.ini file if the file you are trying to upload is bigger than what is allowed:
post_max_size = 8M; make larger if needed
upload_max_filesize = 8M; make larger if needed*
After making these changes make sure to restart your webserver (apache/nginx.)
* upload_max_filesize should never be bigger than post_max_size
......

Max_File_Uploads directive php.ini

Im trying to do a simple file upload. I've done it many times before and it's been fine. For some reason this time I keep getting error UPLOAD_ERR_INI_SIZE coming up. Even though i've uploaded bigger files on the same server before. Here is my PHP.INI:
display_errors = On
short_open_tag = On
memory_limit = 32M
date.timezone = Europe/Paris
upload_max_filesize = 10M
post_max_size = 10M
And my HTML form:
<form action="/settings/upload-image" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="<?=(1024*1024*1024);?>">
<input name="files[]" id="attachfile" type="file" />
<br /><br />
<input type="submit" class="submit" value="Upload New Profile Image">
</form>
And my code:
foreach($files as $file)
{ $ext = strtolower(pathinfo($file[0], PATHINFO_EXTENSION));
if(in_array($ext,$allowed_upload_ext)===TRUE)
{
if(!$file[3]) { // If no error code
//$newFile = $me['id'].".$ext";
$newFile = $file[0];
resizeImage($file[2],PROFILE_IMAGES."/".$newFile,$ext,500);
genThumbFile($file[2],PROFILE_IMAGES."/thumb/".$newFile);
runSQL("UPDATE `users` SET `image`='{$file[0]}' WHERE `id`='{$me['id']}';");
array_push($msgs,"Image uploaded successfully.");
$me = select("SELECT * FROM `users` WHERE `id`='{$me['id']}';",true);
} else {
array_push($msgs,"!".fileError($file[3]));
}
} else {
array_push($msgs,"!The file ".$file[0]." could not be uploaded as it is the wrong file type.");
}
}
The only difference this time is that I am resizing and genorating thumbs with the temporary upload file instead of copying over the file first. Could that be the problem? I dont think so, because if the image is small it works perfectly fine. But I try anything like 2mb and it throws a fit.
Suggestions?
Thanks for ALL YOUR HELP guys. :P
I solved it - Missing line in PHP.INI:
file_uploads = On
Just for anyone who fins this.

Categories