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.
Related
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().
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.
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
......
don't have much experience with php programming and web in general, so I've build this code from tutorials and what it supposed to do is to store data in database, but it seems like it completely ignores any statement(e.g. exception when choosing incorrect data format) and it sort of just refreshes the page after hiting submit button, any ideas how to fix this?
<div id='box'>
<form method='post' enctype='multipart/form-data'>
<?php
if(isset($_FILES['video'])){
$name = $_FILES['video']['name'];
$type = explode('.', $name);
$type = end($type);
$size = $_FILES['video']['size'];
$randon_name = rand();
$tmp = $_FILES['video']['tmp_name'];
if($type != 'mp4' && $type != 'MP4' && $type != 'flv' && $type !='avi'){
$message = "bad format";
}
else{
mysql_query("INSERT INTO videos VALUES('', '$name', 'videos/$randon_name.$type')");
$message = "successful upload";
}
echo $message;
}
?>
Choose file : <br/>
<input type='file' name='video'/>
<br/><br/>
<input type='submit' value='Upload'/>
</form>
</div>
It seems to be the case that you selected a file larger than your upload_max_filesize or post_max_size.
If this is the case then the $_FILES variable is empty and you see nothing. If you select a smaller file you should see something when doing a print_r($_FILES) at the top of your script.
if you run php in apache as a module you can try to add a .htaccess like this:
php_value upload_max_filesize 200M
php_value post_max_size 200M
Otherwise you need to edit your php.ini. As far as i know you cannot set these php.ini values via ini_set().
Yes, I know that there are hundreds of questions similar, but I didn't find a working answer...
The problem is: I want upload multiple files...
The correct way should be this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form enctype="multipart/form-data" method="post" action="?u=1">
<input type="file" name="myFile[]" />
<input type="file" name="myFile[]" />
<input type="file" name="myFile[]" />
<input type="submit" value="Upload!" name="submit"/>
</form>
<?
if ($_GET['u']){
foreach ($_FILES["myFile"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["myFile"]["tmp_name"][$key];
$name = $_FILES["myFile"]["name"][$key];
// here we move it to a directory called data
// you can move it wherever you want
move_uploaded_file($tmp_name, "/data/$name");
} else {
// an error occurred, handle it here
}
}
}
if (!$_FILES){
echo 'WTF?? No files sent?? There\'s a problem! Let\' hope that stack overflow will solve it!';
}
?>
</body>
</html>
The output is:
Notice: Undefined index: myFile in C:\xampp\htdocs\php\prova.php on line 18
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\php\prova.php on line 18
No files sent?? There's a problem! How can I access files uploaded from an array input tag?
I think using $_POSTOR $_FILES instead of $_GET['u'] to verify from submission, would fix the problem...
Also you can use <input type="file" name="myFile[]" multiple /> once instead of so many <input type="file"> for multiple file selection.
NOTE : Check php.ini for the following settings: (Edit as your needs , save & restart server)
file_uploads = On
upload_max_filesize = 2M (its 2 MB file limit by default !!! Exact error occurs as your's if file size > 2MB)
post_max_size = 8M (8 MB limit for post variable by default. Change as per your requirement...)
upload_tmp_dir = "c:/tmp" (Provide read/write permission to temporary opload directory )
This works ok in my wamp server with the above changes & settings... Good Luck !
Well, the easiest way to upload your files is to act as if you had only one, and repeat the process for every other file you have, all you have to do is give an name to your input. I would recommend using a multiple file input :
<input type="file" name="file[]" id="file" multiple>
Then, you can handle the upload with a simple for :
if(isset($_FILES['file']['tmp_name']))
{
//set upload directory
$target_dir = "uploads/";
$num_files = count($_FILES['file']['tmp_name']);
for($i=0; $i < $num_files;$i++)
{
if(!is_uploaded_file($_FILES['file']['tmp_name'][$i]))
{
$messages[] = 'No file uploaded';
}
else
{
if(#copy($_FILES['file']['tmp_name'][$i],$target_dir.'/'.$form['name']->getData()."/".$_FILES['file']['name'][$i]))
{
$messages[] = $_FILES['file']['name'][$i].' uploaded';
}
else
{
$messages[] = 'Uploading '.$_FILES['file']['name'][$i].' Failed';
}
}
}
}
You can use either copy or move_uploaded_file to move the file to your directory.
I checked your code, and found that changing the line:
move_uploaded_file($tmp_name, "/data/$name"); to
move_uploaded_file($tmp_name, "data/$name");
[Changing absolute path to relative path]
does the trick. Now it works fine, in my local server. That should solve it for you.
Courtesy:http://forums.whirlpool.net.au/archive/788971