php - getimagesize() expects parameter 1 to be string, array given -
i using getimagesize validate image type don't know how write script multiple file. basically, have form allow upload of multiple image files below.
<input type="file" name="photo[]" class="file" /> <input type="file" name="photo[]" class="file" /> <input type="file" name="photo[]" class="file" />
then using validate , send via phpmailer.
<?php ob_start(); require("class.phpmailer.php"); $errors = array(); if ('post' === $_server['request_method']) { $firstname = sanitize($_post['firstname']); $lastname = sanitize($_post['lastname']); $email = sanitize($_post['email']); if (empty($firstname)) { $errors['firstname'] = "please provide first name."; } if (empty($lastname)) { $errors['lastname'] = "please provide last name."; } if (!filter_var($email, filter_validate_email)) { $errors['email'] = "please provide valid email address."; } if (count($errors) === 0) { $imageinfo = array(); $my_files = $_files['photo']['tmp_name']; foreach($my_files $single_file) { if(!empty($single_file)) { $imageinfo[$single_file] = getimagesize($single_file); if ($single_file['mime'] != 'image/png' && $single_file['mime'] != 'image/jpeg') { echo "invalid image file"; exit(); } } } foreach($_files['photo']['tmp_name'] $photo) if(!empty($photo)) { $mail->addattachment($photo); $message = 'some message'; $mail = new phpmailer(); $mail->setfrom($email); $mail->addaddress($from); $mail->subject = "submitted"; $mail->body = $message; $mail->wordwrap = 50; } $mail->send(); header("location: thankyou.php"); exit(); }} function sanitize($value) { return trim(strip_tags($value, $problem='')); } ?>
i getting error message of warning: getimagesize() expects parameter 1 string, array given know because of form passing array. how change script work multiple files/arrays? please help. thx.
there more 1 file in $_files['photo']['tmp_name']
array.
the getimagesize()
designed accept 1 file.
so need pass each files function
$imageinfo = array(); $my_files = $_files['photo']['tmp_name']; foreach($my_files $single_file) { if(!empty($single_file)) { $imageinfo[$single_file] = getimagesize($single_file); } } print_r($imageinfo); // have info of files in array.
or can try
$imageinfo0 = getimagesize($_files['photo']['tmp_name'][0]); $imageinfo1 = getimagesize($_files['photo']['tmp_name'][1]); $imageinfo2 = getimagesize($_files['photo']['tmp_name'][2]);
.... , on..
Comments
Post a Comment