0

我在用户使用此注册表单上传图片时遇到问题:

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

这是表单(至少是影响图像上传的部分):

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

1 回答 1

0

如果您要做的是确保用户不会跳过选择要上传的文件,那么您可以使用 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()" ... >

如果这不是你的意思,请澄清你面临的问题。

于 2012-04-18T18:37:24.560 回答