dongsu3138 2018-06-13 09:47
浏览 33
已采纳

如果没有人提供文件,如何停止发送$ _FILES ['name']?

I Have a multipart/form-data form but I not require from users to send me the picture. I am changing the name of the file to random number and the put the path to MySQL. Whenever somebody doesn't put the file, in my database a new recor is beeing created without an extension(obviesly). How to stop this from happening? Sorry for my english.

Here is a a part from the code:

 case 'Sleep Aid': {
      ?>
    <section class="summarySection">
      <div class="summaryHeadingDIV">
        <h1 class="summaryH1">Please check the details below</h1>
      </div>
      <article class="summaryPage">
        <p class="boldSummaryDescr">Brand:</p><p class="paraSummary"><?php echo $brand; ?></p><br>
        <p class="boldSummaryDescr">Model:</p><p class="paraSummary"><?php echo $model; ?></p><br>
        <p class="boldSummaryDescr">Colour:</p><p class="paraSummary"><?php echo $colour; ?></p><br>
        <p class="boldSummaryDescr">Material:</p><p class="paraSummary"><?php echo $material; ?></p><br>
        <p class="boldSummaryDescr">Suitable Age:</p><p class="paraSummary"><?php echo $suitable; ?></p><br>
        <p class="boldSummaryDescr">Purchase date:</p><p class="paraSummary"><?php echo $month . '/' . $year; ?></p><br>
        <p class="boldSummaryDescr">Condition:</p><p class="paraSummary"><?php echo $condition; ?></p><br>
        <p class="boldSummaryDescr">Dimesions:</p><p class="paraSummary"><?php echo $width . ' cm <span class="smallcaps">x</span> ' . $height . ' cm <span class="smallcaps">x</span> ' . $depth . ' cm'; ?></p><br>
        <p class="boldSummaryDescr">Weight:</p><p class="paraSummary"><?php echo $weight . ' kg'; ?></p>
      </article>
      <div class="imageg_container">
        <figure class="img_figure_show">
          <?php 
          if(empty($picture))
          {
            ?>              
            <img src="/_images/no-picture.png" alt="no picture added">
            <?php
          }
          else
          {

            $random_id = rand_img_id();
            add_file(db_user_connect(), $email, $random_id);
            $arry = show_picture(db_user_connect(), $email, $random_id); 
            print "<img src=".$arry["sciezka"]." alt='product picture'>";
          }
          ?>
        </figure>
      </div>
      <div class="clear-left"></div>
      <div class="summaryButtonContainer">
        <a href="javascript:goBack();" class="summaryLinks" title="Go Back">Edit details</a>
        <a href="/_pages/transaction/quotation.php?location=sleepaid&brand=<?php echo urlencode($brand);?>&model=<?php echo urlencode($model)?>&month=<?php echo urlencode($month);?>&year=<?php echo urlencode($year);?>&condition=<?php echo urlencode($condition);?>" class="summaryLinks">Proced to Quote</a>
      </div>
    </section>
    <?php
    break;
  }
  • 写回答

1条回答 默认 最新

  • douren2831 2018-06-13 09:57
    关注

    You need to check the $_FILES['error'] value:

    if ($_FILES['name']['error'] === UPLOAD_ERR_OK) ...
    

    The manual lists all possible values, which you could use to display different messages/do different things: https://secure.php.net/manual/en/features.file-upload.errors.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#微信小程序#的问题:用一个网页显示所有关联的微信小程序数据,包括每个小程序的用户访问量
  • ¥15 root的安卓12系统上,如何使apk获得root或者高级别的系统权限?
  • ¥20 关于#matlab#的问题:如果用MATLAB函数delayseq可以对分数延时,但是延时后波形较原波形有幅度上的改变
  • ¥15 使用华为ENSP软件模拟实现该实验拓扑
  • ¥15 通过程序读取主板上报税口的数据
  • ¥15 matlab修改为并行
  • ¥15 大数据应用基础专业问题
  • ¥20 数据分析出错了,希望有能人看看,解决一下
  • ¥15 尝试访问%1服务的windows注册表时遇到问题。必须先解决此问题,然后才能运行安装过程。(请确认您正在使用管理员权限运行)373
  • ¥15 (关键词-运算放大器)