我正在尝试使以下脚本正常工作,但不断收到以下错误:
警告:getimagesize():第17行的/var/sites/r/domain.co.uk/public_html/dev/test.php中的文件名不能为空 上传文件。
第17行是:list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']);
<?php
error_reporting(E_ALL);
if (isset($_POST['update_photo'])) {
$uploadpath = '../operator_images/'; // directory to store the uploaded files
$max_size = 2000; // maximum file size, in KiloBytes
$alwidth = 200; // maximum allowed width, in pixels
$alheight = 200; // maximum allowed height, in pixels
$allowtype = array('bmp', 'gif', 'jpg', 'jpe', 'png'); // allowed extensions
if(isset($_FILES['fileup']) && strlen($_FILES['fileup']['name']) > 1) {
$uploadpath = $uploadpath . date('Ymdhis') . basename( $_FILES['fileup']['name']); // gets the file name
$sepext = explode('.', strtolower($_FILES['fileup']['name']));
$type = end($sepext); // gets extension
list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']); // gets image width and height
$err = ''; // to store the errors
// Checks if the file has allowed type, size, width and height (for images)
if(!in_array($type, $allowtype)) $err .= '<span style="color: #FFFFFF; ">The file: <b>'. $_FILES['fileup']['name']. '</b> not has the allowed extension type.</span>';
if($_FILES['fileup']['size'] > $max_size*1000) $err .= '<span style="color: #FFFFFF; "><br/>Maximum file size must be: '. $max_size. ' KB.</span>';
if(isset($width) && isset($height) && ($width >= $alwidth || $height >= $alheight)) $err .= '<span style="color: #FFFFFF; "><br/>The maximum Width x Height must be: '. $alwidth. ' x '. $alheight .'</span>';
// If no errors, upload the image, else, output the errors
if($err == '') {
if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)) {
echo '';
if(isset($width) && isset($height)) echo '';
echo '';
}
else echo '<b>Unable to upload the file.</b>';
}
else echo $err;
}
}
echo "<form action='test.php' method='post' enctype='multipart/form-data' data-abide>
<div class='input-wrapper'>
<label style='color: #000000; ' for='filebutton'>Select File</label>
<input id='file' name='fileup' type='file'>
</label>
</div>
<div><button type='submit' class='button expand radius success' name='update_photo'>Upload Photo</button></div>
</form>";
?>