I need to upload a video file. Here's my code
if(($_FILES["file"]["type"]=="application/octet-stream") || ($_FILES["file"]["type"]=="video/x-ms-wmv"))
{
if($_FILES["file"]["error"] > 0)
{
echo "Error: ".$_FILES["file"]["error"]."<br />";
}
else if(file_exists("videos/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],"videos/".$_FILES["file"]["name"]);
$filename=$_FILES["file"]["name"];
$type=$_FILES["file"]["type"];
$size=($_FILES["file"]["size"]/1024);
$path="".$_FILES["file"]["name"];
if(($ins=mysql_query("insert into achieva_video values('','".$_REQUEST['vname']."','".$_REQUEST['courid']."','".$filename."','".$path."','".$size."','".$type."','Active')"))==true)
{
header("location:viewcoursevideo.php?ins=1");
}
else
{
echo("<script>alert('Failure Please try again later');</script>");
}
}
}
else
{
echo "<script>alert('Invalid File Type');</script>)";
}
I'm bit confused with this warning message when I try to upload a video file.
"PHP Warning: POST Content-Length of 9311816 bytes exceeds the limit of 8388608 bytes in Unknown on line 0"
I've set the following preferences in the php ini:
memory limit = 150M
upload file size = 120M
post max size = 120M
The file has not been updated. it takes long time and just shows this warning.
the message seems clear: you have an upload limit set to 8M (8388608 bytes) and you are uploading a file of 9M (9311816 bytes). Are you really sure these settings in php.ini are working?
memory limit = 150M
upload file size = 120M
post max size = 120M
Shouldn't it be like this? (underscores, max!)
memory_limit = 150M
upload_max_filesize = 120M
post_max_size = 120M
Related
I am uploading image files in PHP but I found out that I was unable to get a file size of some images captured from one mobile device. I can get the file name but not the size so can anyone tell what likely will be the problem or how to fix it to be able to get the file size?
When I check the size in my system its size is in MB while other of my images are in KB.
<?php
if (isset($_FILES["file"]["name"][1]) && !empty($_FILES["file"]["name"])) {
$fileext = ["jpg", "jpeg", "png", "bif", "gif", "bmp"];
for ($i = 1; $i < count($_FILES["file"]["name"]); $i++) {
$name = $_FILES["file"]["name"][$i];
$type = $_FILES["file"]["type"][$i];
$size = $_FILES["file"]["size"][$i];
$path = $_FILES["file"]["tmp_name"][$i];
$ext = end(explode('.', strtolower($name)));
//checking file supported type
if (in_array($ext, $fileext)) {
echo $name . "<br>";
} else {
echo "file type not supported!";
}
}
}
?>
As for the file upload error:
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'r unable to access your php.ini you can try:
ini_set('upload_max_filesize', '10M');
ini_set('post_max_size', '10M');
ini_set('max_input_time', 300);
ini_set('max_execution_time', 300);
also incressing memory_limit might be usefull..
I'm a PHP newbie and have written a script to process form uploads. It works for small files(less than 1Mb). However when I try to upload an ~4Mb pdf file it returns an error message. What am I doing wrong?
PS: I ran php_info, got the value of "upload_tmp_dir" and set it to a directory owned by the apache process(www-data)
My client-side code is
<form action="upper.php" method="post" enctype="multipart/form-data">
<input type="file" name="myFile"><br>
<input type="submit" value="Upload">
</form>
Upper.php contains
define("UPLOAD_DIR", "/var/www/html/upload/");
if (!empty($_FILES["myFile"])) {
$myFile = $_FILES["myFile"];
if ($myFile["error"] !== UPLOAD_ERR_OK) {
echo "Error is " . $myFile["error"];
//echo "<p>An error occurred.</p>";
exit;
}
$name = preg_replace("/[^A-Z0-9._-]/i", "_", $myFile["name"]);
// don't overwrite an existing file
$i = 0;
$parts = pathinfo($name);
while (file_exists(UPLOAD_DIR . $name)) {
$i++;
$name = $parts["filename"] . "-" . $i . "." . $parts["extension"];
}
// preserve file from temporary directory
$success = move_uploaded_file($myFile["tmp_name"], UPLOAD_DIR . $name);
if (!$success) {
echo "<p>Unable to save file.</p>";
exit;
}
// set proper permissions on the new file
chmod(UPLOAD_DIR . $name, 0644);
}
Most probably you have wrong config in you php.ini file.
You need to set
; Maximum allowed size for uploaded files.
upload_max_filesize = 40M
; Must be greater than or equal to upload_max_filesize
post_max_size = 40M
its already described here: PHP change the maximum upload file size
You ned to set values in php.in file.
Open the file,
Find upload_max_filesize and post_max_size lines.
Change this two value. (M= MB)
; Maximum allowed size for uploaded files.
upload_max_filesize = 20M
; Must be greater than or equal to upload_max_filesize
post_max_size = 20M
Restart the sever for effect.
Note:
You can set any number. But not use any decimal value.
Open the php.ini file in NOTEPAD. Don't user wordpad or any word processor.
I am trying to upload PDF file using PHP Script, The below is my code. It works perfectly for any file which is less than 1 MB, but when I upload more than 1 MB, It goes to the else statement and gives this message - "Max File Size Upload Limit Reached, Please Select Any Other File".
I have already seen php.ini configuration, this is set at 16M. Please help
ini_set('upload_max_filesize', '16M');
ini_set('post_max_size', '16M');
//$ImageName=addslashes($_REQUEST['txtimagename']);
//$ImageTitle=addslashes($_REQUEST['txtimagetitle']);
$filepath="files/";
//$filedt=date("dmYhisu")."_.".pathinfo($_FILES['imagefile']['name'], PATHINFO_EXTENSION);
$filedt=$_POST['vehregistration'].".".pathinfo($_FILES['imagefile']['name'], PATHINFO_EXTENSION);
//basename($_FILES['photoimg']['name']);
$destination_img=$_POST['vehregistration'].".".pathinfo($_FILES['imagefile']['name'], PATHINFO_EXTENSION);
$filename=$filepath.$destination_img;
//$filename=$filepath.basename($_FILES['Photo']['name']);
//echo "$filepath".$_FILES[" imagefile "][" name "];
if(move_uploaded_file($_FILES["imagefile"]["tmp_name"], $filename))
{
//echo $filedt;exit;
//rename($_FILES['Photo']['tmp_name'],$filedt);
return $filedt;
}
else
{
echo "Max File Size Upload Limit Reached, Please Select Any Other File";
}
}
Add this in else condition $_FILES['imagefile']['error'] and see what is exact error . For more details http://php.net/manual/en/features.file-upload.errors.php
Instead of using ini_setuse $_FILES["imagefile"]["size"]
$fileSize = $_FILES["imagefile"]["size"]; // File size in bytes
$maxFileSz = 16777216; // set your max file size (in bytes) in this case 16MB
if($fileSize <= $maxFileSz) {
// everything is okay... keep processing
} else {
echo 'Max File Size Upload Limit Exceeded, Please Select Any Other File';
}
I am facing problem uploading files, getting errors after some time.
I am uploading files and inserting details into database about image like name date etc.
What happens is that till no of uploaded file is 27 everything works
well but when I try to upload more than 27 file it start showing errors
like
Warning: move_uploaded_file(../../images/2015/05/imvsa/kexk.jpg):
failed to open stream: No such file or directory
Warning: move_uploaded_file(): Unable to move
'D:\wamp\tmp\php3635.tmp' to '../../images/2015/05/imvsa/kexk.jpg'
my php.ini
max_execution_time = 1440
max_input_time = 1440
post_max_size = 1024M
upload_max_filesize = 1024M
max_file_uploads = 10000
session.save_path = "d:/wamp/tmp"
session.gc_maxlifetime = 7200
memory_limit = 512M
If I truncate my database table then it starts working uptill row 27 and again it starts to fail.
my script
if($_FILES['image']['size']<5242880&&getimagesize($_FILES['image'])!=false)
{
if(!is_dir('../../images/2015/05/'))
{
$mkdir = mkdir('../../images/2015/05/', 0777, true);
}
$info = pathinfo($_FILES['image']['name']);
$image = $_FILES['image']['name'];
$ext = $info['extension'];
$temp_file = $_FILES['image']['tmp_name'];
$img_target ='../../images/2015/05/'.$image.'.'.$ext;
$upload = move_uploaded_file($temp_file, $img_target);
}
// and now I do Insert in database
Please see and suggest any possible way to make it work, I an going to be uploading hundreds of image in a day with max size of 5MB.
Thanks
Try this:
if(!is_dir('../../images/2015/05/imvsa/')){
$mkdir = mkdir('../../images/2015/05/imvsa/', 0777, true);
}
here is the code that i use to upload files and unzip them in a directory.
But the problem is that it seems to be very slow on files greater than 5MB.
I think it doesnt have to do with the network because it is in localhost computer.
Do I need to edit any parameter in php.ini file or apache or any other workarround?
$target_path = "../somepath/";
$target_path .= JRequest::getVar('uploadedDirectory')."/";
$target_Main_path= JRequest::getVar('uploadedDirectory')."/";
$folderName = $_FILES['uploadedfile']['name'];
$target_path = $target_path . basename($folderName);
//upload file
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path."/")) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
$zip = new ZipArchive;
$res = $zip->open($target_path);
$target_path = str_replace(".zip", "", $target_path);
echo $target_path;
if ($res === TRUE) {
$zip->extractTo($target_path."/");
$zip->close();
echo "ok";
} else {
echo "failed";
}
When handling file uploads ther are a lot of factors to consider. These include PHP settings:
max_input_time
max_execution_time
upload_max_filesize
post_max_size
Execution time can affect the upload if for example, you have a slow upload speed resulting in a timeout.
File size can cause problems if the upload is larger than the upload_max_filesize like wise if your file size + the rest of the post data exceeds post_max_size.
Zip uses a lot of memory in the archive/extraction processes and could easily exceed the memory allocated to PHP -so that would be worth checking as well.
I would start with this page and note some of the comments.