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
Related
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
so I created simple form to upload files and dd the $request->file
<form
action="/videos"
method="post"
enctype="multipart/form-data"
id="upload_form"
name="upload_form"
>
#csrf
<input type="file" name="avatar" />
<input type="submit" value="submit" />
</form>
dd($request->file('avatar');
if the video is above 1 mb but less than 8 mb it get's uploaded with error 1 and a size of 0 mb if the video is above 8 mb I get an error
Illuminate\Http\Exceptions\PostTooLargeException
PHP Warning: POST Content-Length of 21712952 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
this is my php.ini file inside laravel
post_max_size = 100M
; upload_max_filesize = 60M
variables_order = EGPCS
max_execution_time = 3600s
memory_limit = 100M
upload_max_filesize = 60M
Your php.ini config is fine. The problem is in the nginx config.
You must increase the client_max_body_size. The default value of it is 1 MB per file.
Add the following in your default.conf of your nginx project:
server {
...
client_max_body_size 128M;
...
}
I use Laravel 6.2. I try to upload a video. The size is ~700mb, but when I submit the form I receive the following error in Chrome:
The connection was reset
I tried to upload a video which has ~5mb size and it worked fine.
I disabled XCache, but it did not work.
P.s: Post_max_size and upload file size is 2gb
Try the following:
Apache: Edit your httpd.conf file, and increase max_execution_time as well as max_input_time:
<Directory "[path/to/this/directory]">
php_value upload_max_filesize 2000M
php_value post_max_size 2000M
php_value max_execution_time 600
php_value max_input_time 600
</Directory>
PHP: you can also increase time and size in your php.ini file:
post_max_size = 2G
memory_limit = 512M
max_execution_time = 36000
max_input_time = 60
Then, restart your Apache server and try again.
There is a lot of data being submitted no file uploads and the $_SERVER['CONTENT_LENGTH'] is being exceeded. Can this be increased?
There are 2 different places you can set it:
php.ini
post_max_size=20M
upload_max_filesize=20M
.htaccess / httpd.conf / virtualhost include
php_value post_max_size 20M
php_value upload_max_filesize 20M
Which one to use depends on what you have access to.
.htaccess will not require a server restart, but php.ini and the other apache conf files will.
I had a situation when variables went missing from POST and all of the above answers didn't help. It turned out that
max_input_vars=1000
was set by default and POST in question had more than that.
This may be a problem.
; Maximum allowed size for uploaded files.
upload_max_filesize = 40M
; Must be greater than or equal to upload_max_filesize
post_max_size = 40M
You can do this with .htaccess:
php_value upload_max_filesize 20M
php_value post_max_size 20M
We can Increasing the maximum limit using .htaccess file.
php_value session.gc_maxlifetime 10800
php_value max_input_time 10800
php_value max_execution_time 10800
php_value upload_max_filesize 110M
php_value post_max_size 120M
If sometimes other way are not working, this way is working perfect.
You can increase that in php.ini
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M
I had been facing similar problem in downloading big files this works fine for me now:
safe_mode = off
max_input_time = 9000
memory_limit = 1073741824
post_max_size = 1073741824
file_uploads = On
upload_max_filesize = 1073741824
max_file_uploads = 100
allow_url_fopen = On
Hope this helps.
You can specify both max post size and max file size limit in php.ini
post_max_size = 64M
upload_max_filesize = 64M
Try
LimitRequestBody 1024000000
php.ini
Change setting max_input_vars from default 1000 to 10000 for enought json post data.
It worked for me.
max_input_vars=10000
Only add the below 3 lines in .htaccess file, which is in your root folder of the project.
php_value memory_limit 500M
php_value post_max_size 500M
php_value upload_max_filesize 500M
It will completely assist you in resolving your problem.
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.