<?php
if(isset($_POST['submitted'])){
if(isset($_FILES['upload'])){
$allowed=array('image/pjepg','image/jpeg','image/JPG','image/X-PNG','image/PNG','image/png');
if(in_array($_FILES['upload'][type],$allowed)){
if(move_uploaded_file($_FILES['upload']['tmp_name'],"../upload/{$_FILES['upload']['name']}")){
echo '<p><em> The file has been uploaded!</em></p>';
}
else {
echo '<p class="error">Please upload a JPEG or PNG image. </p>';
}
}
isset($_FILES['upload'])
if($_FILES['upload']['error']>0){
echo '<p class="error">The file could not be uploaded because: <strong>';
switch ($_FILES['upload']['error']) {
case 1:
print 'the file exceeds the upload_max_filesize setting in php.ini.';
break;
case 2:
print 'the file exceeds the MAX_FILE_SIZE setting in HTML form.';
break;
case 3:
print 'the file was only partially uploaded.';
break;
case 4:
print 'No file was uploaded.';
break;
case 5:
print 'No temporary folder was availiable.';
break;
case 6:
print 'Unable to write to the disk.';
break;
case 7:
print 'File uploaded stopped.';
break;
default:
print 'A system error occurred.';
break;
}
print '</strong></p>';
}
if((file_exists($_FILES['upload']['tmp_name'])) && (is_file($_FILES['upload']['tmp_name']))){
unlink($_FILES['upload']['tmp_name']);
}
}
?>
当我运行时,我得到:
解析错误:语法错误,第15行C:\ wamp \ www \ project \ uploadctrl.php中的意外T_IF
我无法在语法中找到任何错误。我在代码上搜索所有内容但我没有找到任何内容。任何人都可以帮忙???
答案 0 :(得分:1)
您:
isset($_FILES['upload'])
需要:
isset($_FILES['upload']);
确实说第15行,通常错误就在那一行之前。