Php 图像上传脚本
我正在尝试使以下脚本正常工作,但不断出现以下错误: 警告:getimagesize():第17行/var/sites/r/domain.co.uk/public_html/dev/test.php中的文件名不能为空 上传文件。 第17行是:Php 图像上传脚本,php,Php,我正在尝试使以下脚本正常工作,但不断出现以下错误: 警告:getimagesize():第17行/var/sites/r/domain.co.uk/public_html/dev/test.php中的文件名不能为空 上传文件。 第17行是:list($width,$height)=getimagesize($\u FILES['fileup']['tmp\u name']) tmp\u name来自哪里?我不确定。我不是PHP专家。此代码已运行,然后突然停止。我已经和主机公司打了一个电话,看看那
list($width,$height)=getimagesize($\u FILES['fileup']['tmp\u name'])代码>
tmp\u name
来自哪里?我不确定。我不是PHP专家。此代码已运行,然后突然停止。我已经和主机公司打了一个电话,看看那里是否有任何变化。(同时,你可以试着找出$\u文件['fileup']
(和$\u文件['file']
),我已经把这一点缩小到主机的问题上,因为同样的脚本在其他主机上工作得很好。)。
<?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>";
?>