简体   繁体   English

照片上传不上传大于2MB的文件

[英]Photo upload not uploading files bigger than 2MB

I have a php file upload in place in which the forms target is an iframe. 我有一个PHP文件上传的地方,其中的形式目标是一个iframe。

It uploads files less than 2mb fine. 它将上传小于2mb的文件。 But anything larger it will not upload. 但是任何较大的内容都不会上传。 I cant see any reason behind this in the code. 我看不到代码背后的任何原因。

<div id="upload_wrapper">

<img src="../images/logo.png" alt="logo5" width="" height="" style="padding:0px;" />
<h3>Profile picture upload</h3>

  <form id="upload" name="upload" enctype="multipart/form-data" method="post" action="index.php" target="upload_target">
    <input name="folder" type="hidden" value="<?php echo $folder ?>"  />
    <input name="filename" type="hidden" value="<?php echo $filename ?>"  />
    <input name="uploaded_file" type="file" size="5120" id="uploaded_file"  />
    <input id="sent" name="sent" type="submit"  value="Upload" />
  </form>
</div>
<div id="loading" style="background:url(ajax-loader.gif) no-repeat left; height:50px; width:370px; display:none;">
  <p style="margin-left:40px; padding-top:15px;">Uploading File... Please wait</p>
</div>
<div id="image_wrapper" style="display:none;"><p id="preview"></p></div>
<iframe id="upload_target" name="upload_target" style="width:10px; height:10px; display:none"></iframe>
</div>

And heres the php upload code 和继承人的PHP上传代码

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

$targetFolder = $_POST['folder'] . "/";
$filename2 = $_POST['filename'];

if (!is_dir($targetFolder)) 
{
    mkdir($targetFolder, 0777);
}

    $tempFile = $_FILES['uploaded_file']['tmp_name'];
    $targetPath = dirname(__FILE__) . '/' . $targetFolder;
    $targetFile = rtrim($targetPath,'/') . '/' . $_FILES['uploaded_file']['name'];

    // Validate the file type
    $fileTypes = array('jpg'); // File extensions
    $fileParts = pathinfo($_FILES['uploaded_file']['name']);

    if (in_array($fileParts['extension'],$fileTypes)) 
    {
        $uploadfile = $targetFolder. basename($filename2 .".".$fileParts['extension']);
         move_uploaded_file($tempFile,$uploadfile);
         $fileName = $uploadfile;
    }

    echo "<div id='filename'>$fileName</div>";

}

也许更改您的php服务器的配置会有所帮助(例如10MB):

ini_set('upload_max_filesize', '10M');

make sure your php.ini configuration support large files. 确保您的php.ini配置支持大文件。 upload_max_filesize and post_max_size also you can change the configuration temporary using ini_set before you handle the upload process. upload_max_filesizepost_max_size也可以在处理上传过程之前使用ini_set临时更改配置。

try this may be it would work put it in your code and then try 尝试这可能是可行的将其放入您的代码中,然后尝试

 define ("MAX_SIZE","1000"); // put your max size value 
 $size=filesize($_FILES['uploaded_file']['tmp_name']);

 //compare the size with the maxim size we defined and print error if bigger
  if ($size > MAX_SIZE*1024)
    {
echo '<h1>You have exceeded the size limit!</h1>';
$errors=1;
     }

or else you have to edit in php.ini found in document root/php/php.ini 否则,您必须在文件root / php / php.ini中找到的php.ini中进行编辑

You can change your server setting. 您可以更改服务器设置。 Look for the php.ini file and search "upload_max_filesize" 查找php.ini文件并搜索“ upload_max_filesize”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM