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>
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.