简体   繁体   English

我需要使用php上传文件到表单吗?

[英]What do I need to upload a file to a form using 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. 我正在创建一个工作申请表,用户在其中添加他的简历,并将其附加到电子邮件中,对于小于1 MB的文件,一切正常,如果我单击“提交”,则更多,服务器花费了很多时间,然后给了我一个服务器超时错误。

This is the html: 这是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: 这是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. 我猜问题是,当我单击表单提交按钮时,文件开始上传的时间比服务器超时要多一些,是否有一种方式让用户等待文件首先上传(也许使用进度条) ,然后上传后,用户单击“提交表单”并将其发送到电子邮件,否则问题仍然存在。

PHP has several configuration options to limit resources consumed by scripts. PHP有几个配置选项来限制脚本消耗的资源。 By default, PHP is set to allow uploads of files with a size of 2MB or less. 默认情况下,PHP设置为允许上传大小为2MB或更小的文件。

Try increasing the following values in php.ini, for example: 例如,尝试增加php.ini中的以下值:

memory_limit = 32M
upload_max_filesize = 24M
post_max_size = 32M

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

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