drju37335 2012-04-18 18:26
浏览 58

使用表单上传图像

I have been having problems with users uploading their images using this registration form:

<?php
errors = array();
$missing = array();
// check if the form has been submitted
if (isset($_POST{'submit'}) && !empty($_FILES)){
    require_once('./classes/Ps2/Upload.php');
 try {
    $upload = new Ps2_Upload('my address');
    $upload->move();
    $messages = $upload->getMessages();
  }catch (Exception $e) {
    echo $e->getMessage();
  }

   $tmp_name = $_FILES['image']['tmp_name'];
   $type = $_FILES['image']['type'];
   $name = $_FILES['image']['name'];
  $size = $_FILES['image']['size'];
   $names = $_POST['names'];
   $number = $_POST['number'];
   $email = $_POST['email'];
   $seminar = $_POST['seminar'];
   $address = $_POST['address'];

$response = recaptcha_check_answer($private_key, $_SERVER['REMOTE_ADDR'],       $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
if (!$response->is_valid) {
$errors['recaptcha'] = true;
}
<?

And here is the form (at least the part that effects the image uploading):

<form id="register" name="register" method="post" enctype="multipart/form-data" action="">
  <p>
  <fieldset><legend class="caption">Registration Details</legend>
    <p>
      <label for="image">Upload image photograph:
      <?php if ($missing && in_array('image', $missing)) { ?>
<span class="warning">Please pick your passport</span>
<?php } ?>
      </label>
    <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max; ?>">
    <input name="image" id="image" type="file" value="image" tabindex="1">
      </p>
  • 写回答

1条回答 默认 最新

  • dongyanzhui0524 2012-04-18 18:37
    关注

    If what you're trying to do is make sure that the user doesn't skip choosing a file to upload, then you could do that check with Javascript:

    <script type="text/javascript">
        function checkImage()
        {
            if (document.getElementById('image').value == "")
            {
                alert("Please select an image to upload.");
                return false;
            }
    
            return true;
        }
    </script>
    
    <form onsubmit="return checkImage()" ... >
    

    If that's not what you mean, please clarify the problem you're facing.

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)