1

我有一个 php 文件上传,其中表单目标是 iframe。

它可以上传小于 2mb 的文件。但任何更大的东西都不会上传。我在代码中看不到这背后的任何原因。

<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>

这是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>";

}
4

4 回答 4

1

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

ini_set('upload_max_filesize', '10M');
于 2013-07-18T08:00:05.933 回答
0

确保您的 php.ini 配置支持大文件。upload_max_filesize您还post_max_size可以ini_set在处理上传过程之前临时更改配置。

于 2013-07-18T08:01:42.300 回答
0

试试这个可能会起作用把它放在你的代码中,然后尝试

 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;
     }

否则您必须在文档 root/php/php.ini 中找到的 php.ini 中进行编辑

于 2013-07-18T08:07:10.313 回答
0

您可以更改服务器设置。查找 php.ini 文件并搜索“upload_max_filesize”

于 2013-07-18T08:30:52.190 回答