dpztth71739 2019-08-08 21:03
浏览 90

使用php将文件上传到表单需要什么?

I'm creating a job application form in which a user adds his resume and it's attached to an email, everything worked fine for file less than 1 MB size, if it's more when I click submit the server takes so much time then gives me a server timeout error.

This is the html:

      <div class="form-group">
        <label for="personalCV">CV</label>
        <input
         name="personalCV"
         type="file"
         class="form-control"
         id="personalCV"
         placeholder="Attach CV"
         style="height: auto;"

         value="<?php if (isset($personalCV)){echo $personalCV;} ?>"
         required>
         <span>File Shouldn't exceed 2MB, and must be of formats .doc, .docx, .pdf</span>

      </div>

This is the php:

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

    //assign variables//
    $firstName = filter_var($_POST['firstName'] , FILTER_SANITIZE_STRING);
    $lastName = filter_var($_POST['lastName'] , FILTER_SANITIZE_STRING);
    $email = filter_var($_POST['userEmail'] , FILTER_SANITIZE_EMAIL);
    $phoneNum = filter_var($_POST['phoneNum'] , FILTER_SANITIZE_NUMBER_INT);
    $position = $jobTitle;
    $message = filter_var($_POST['message'] , FILTER_SANITIZE_STRING);
    $path = 'upload/' . $_FILES["personalCV"]["name"];
    move_uploaded_file($_FILES["personalCV"]["tmp_name"], $path);

I guess the problem is that when i click on the form submit button the file starts to upload which takes some time more than the server timeout, is there a way where the user waits for the file to upload first (maybe use a progress bar), then after it uploads user clicks submit form and it's sent to email, or will the problem still persist.

  • 写回答

1条回答 默认 最新

  • duanmu2013 2019-08-09 01:23
    关注

    PHP has several configuration options to limit resources consumed by scripts. By default, PHP is set to allow uploads of files with a size of 2MB or less.

    Try increasing the following values in php.ini, for example:

    memory_limit = 32M
    upload_max_filesize = 24M
    post_max_size = 32M
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Jenkins+k8s部署slave节点offline
  • ¥15 微信小游戏反编译后,出现找不到分包的情况
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题