I programmed a page to upload files like videos, But I have a problem with large file more than 2GB
When I upload file less than 2GB it's working fine with out any problem, But when I try large file I get empty array with error code 7
array(1) {
["file"]=> array(5) {
["name"]=> string(15) "12345648465.mp4"
["type"]=> string(0) ""
["tmp_name"]=> string(0) ""
["error"]=> int(7)
["size"]=> int(0)
}
}
php code :
<?php
include '../conn.php';
if(isset($_POST['submit'])){
$videos_path = '../testvideos/';
$video = $_FILES["file"]["name"];
$tmp_video = $_FILES['file']['tmp_name'];
$name = explode('.',$video);
$real_name = $name[0];
$video_file = $videos_path . $real_name;
if (!file_exists($video_file)) {
var_dump($_FILES);
if (is_uploaded_file($tmp_video)) {
mkdir($video_file, 0777, true);
if(move_uploaded_file($tmp_video,$video_file.'/'.$video)){
print_r($real_name);
}else{
print_r($_FILES);
}
}
}else {
echo '<script>alert(file already exist);</script>';
}
}
?>
HTML :
<!DOCTYPE html>
<html>
<head>
<title>Test Upload</title>
</head>
<body>
<div>
<form action="index.php?action=upload" method="post" id="upload-form" enctype="multipart/form-data">
<div class="file-area">
<input type="file" id="file" name="file" multiple accept="video/mp4,video/*" />
</div>
<div class="simple-field">
<input type="submit" name="submit" id="submit" />
</div>
</form>
</div>
</body>
</html>
.htaccess file :
<IfModule php8_module>
php_flag display_errors On
php_value max_execution_time 20000
php_value max_input_time 20000
php_value max_input_vars 1000
php_value memory_limit 8G
php_value post_max_size 4G
php_value session.gc_maxlifetime 1440
php_value upload_max_filesize 20G
php_flag zlib.output_compression Off
</IfModule>
<IfModule lsapi_module>
php_flag display_errors On
php_value max_execution_time 20000
php_value max_input_time 20000
php_value max_input_vars 1000
php_value memory_limit 8G
php_value post_max_size 4G
php_value session.gc_maxlifetime 1440
php_value upload_max_filesize 20G
php_flag zlib.output_compression Off
</IfModule>
limitRequestBody 5368709120
there's nothing in php error log and apache logs
I use WHM & CPanel with centos7 on my own server
I tried to change
php_value memory_limit
php_value post_max_size
with different values but same thing
Problem solved by increase space in /tmp directory
Centos7 /RHEL :
# mount -t tmpfs -o size=10485760000,mode=1777 overflow /tmp
Related
In my Codeigniter based code, I have taken the following measures:
MultiPHP INI Editor in Cpanel
asp_tags = Off
display_errors = Off
max_execution_time = 300
max_input_time = 600
max_input_vars = 1000
memory_limit = 512M
post_max_size = 128M
session.gc_maxlifetime = 1440
session.save_path = "/var/cpanel/php/sessions/ea-php56"
upload_max_filesize = 128M
zlib.output_compression = Off
.htaccess in Home Directory
<IfModule php5_module>
php_flag asp_tags Off
php_flag display_errors Off
php_value max_execution_time 20000
php_value max_input_time 20000
php_value max_input_vars 1000
php_value memory_limit 2G
php_value post_max_size 2G
php_value session.gc_maxlifetime 20000
php_value session.save_path "/var/cpanel/php/sessions/ea-php56"
php_value upload_max_filesize 2G
php_flag zlib.output_compression Off
</IfModule>
<IfModule lsapi_module>
php_flag asp_tags Off
php_flag display_errors Off
php_value max_execution_time 20000
php_value max_input_time 20000
php_value max_input_vars 1000
php_value memory_limit 2G
php_value post_max_size 2G
php_value session.gc_maxlifetime 20000
php_value session.save_path "/var/cpanel/php/sessions/ea-php56"
php_value upload_max_filesize 2G
php_flag zlib.output_compression Off
</IfModule>
First lines in Controller and Model:
ini_set('post_max_size', '64M');
ini_set('upload_max_filesize', '64M');
ini_set("pcre.backtrack_limit", "100000000");
ini_set("max_allowed_packet ", "2G");
ini_set("max_execution_time ", "20000");
ini_set('max_input_time','20000');
ini_set('memory_limit', '2G');
set_time_limit(0);
$config before file upload
$config=array(
'upload_path'=>$_SERVER['DOCUMENT_ROOT']."/assets/uploads/rpt/",
'allowed_types'=>"rpt",
'overwrite' => TRUE,
'max_size' => '100000000',
'file_name' =>$filename
);
$this->load->library('upload', $config);
$this->upload->initialize($config);
if($this->upload->do_upload('rpt1'))
{
// do something
}
else
{
return "<div class='alert alert-danger'>".$this->upload->display_errors()."</div>";
}
Still I am getting the below message on uploading file greater than 2 MB size:
The uploaded file exceeds the maximum allowed size in your PHP
configuration file.
What else is the solution?
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 = 50M
; Must be greater than or equal to upload_max_filesize
post_max_size = 50M
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.
OR
Even you can set in .htaccess file of project
php_value upload_max_filesize 50M
php_value post_max_size 50M
Finally I opened the WHM to edit php INI settings. making changes there corrected the issue.
I have faced issue of upload_max_filesize , I have updated php.ini file on server with adding following.
memory_limit = 500M
post_max_size = 500M
file_uploads = On
max_execution_time = 600
max_input_time = 900
upload_max_filesize =500M
Also I have updated .htaccess file like..
<IfModule php7_module>
php_flag display_errors
php_value post_max_size 500M
php_value max_execution_time 330
php_value max_input_time 260
php_value max_input_vars 1000
php_value memory_limit 500M
php_value session.gc_maxlifetime 1440
php_value session.save_path "/var/cpanel/php/sessions/ea-php70"
php_value upload_max_filesize 500M
</IfModule>
But still i am getting same error The uploaded file exceeds the upload_max_filesize directive in php.ini , I just trying to upload 2MB video but getting same error.
Why does it i happen i don't know , I have also words with server support center and they told me that they have set 500MB max_upload_size.
Hello and thanks for reading this.
So my main problem is that i need to allow users to send an maximum 10mb file(doc / pdf). But if someone uploads a file bigger then 2 mb it fails to send the email, but the file is uploaded on server in wpcf7_uploads.
This is my setup
[file file-907 limit:10mb filetypes:doc|docx|pdf]
In file attachment
[file-907]
I also set up htacces to this
<IfModule mod_php5.c>
php_value post_max_size 200M
php_value upload_max_filesize 200M
php_value memory_limit 300M
php_value max_execution_time 259200
php_value max_input_time 259200
php_value session.gc_maxlifetime 1200
</IfModule>
And now i am out of ideas and in need of help.
Add this deatil php.ini file:
post_max_size = 25M
default_mimetype = "text/html"
default_charset = "UTF-8"
file_uploads = On
upload_max_filesize = 25M
allow_url_fopen = On
user_agent="PHP"
default_socket_timeout = 60`
I am currently using the .htacces method to achive this
Here is what I am using so far
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300
But each time I am getting error
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
The better way is to change its settings through php.ini file. Find/change following options:
upload_max_filesize = 100M
post_max_size = 100M
Save this code in any php file and update it in the plugins directory and activate that plugin:
ini_set('upload_max_size','256M');
ini_set('post_max_size','256M');
ini_set('max_Execution_time','600');
You can put these lines before or after any other script in you .htaccess file. Save it and upload. That's it! Hope this helps!
#Change upload limits
php_value memory_limit 34M
php_value post_max_size 33M
php_value upload_max_filesize 32M
php_value max_execution_time 600
#Change upload limits end
In your php.ini file insert the following lines of code into it if it is not there and increase upload_max_filesize according to your requirements:
memory_limit = 100M
upload_max_filesize = 200M
post_max_size = 100M
file_uploads = On
Ok great, I just got it!!
Adding the followwing code in "wp-admin" folder does the trick
memory_limit = 100M
upload_max_filesize = 200M
post_max_size = 100M
As a summary of the above:
I add the following code in the .htaccess file in the directory wp-admin:
php_value memory_limit 34M
php_value post_max_size 33M
php_value upload_max_filesize 32M
php_value max_execution_time 600
and it worked.
I can't upload PDF file using PHP.
I have tried to get the name of file only for testing.
HTML:
<form action="add.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" value="Upload" name="submit" />
</form>
add.php:
<?php
echo $_FILES['file']['tmp_name'];
?>
I got an error message:
"Notice: Undefined index: file in C:\wamp\www...".
but it worked for another files.
Please help me!
Your code looks fine, so its probably a problem to do with file size limits.
Add the following to .htaccess and see if it makes any difference.
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300
You could also make the changes in your php.ini like this:
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300
max_input_time = 300