Php 警报不';行不通
我试图在php文件中弹出一个警报,如果用户没有在input元素中上传文件 index.php中的源代码:Php 警报不';行不通,php,html,file,upload,alert,Php,Html,File,Upload,Alert,我试图在php文件中弹出一个警报,如果用户没有在input元素中上传文件 index.php中的源代码: <input type='file' name="imgInp" id="imgInp" accept=".jpg, .png, .jpeg|images/*"/> <img style="max-height: 400px; max-width: 400px;" id="blah" src="#" alt="your image" /> 在提交的php文件中:
<input type='file' name="imgInp" id="imgInp" accept=".jpg, .png, .jpeg|images/*"/>
<img style="max-height: 400px; max-width: 400px;" id="blah" src="#" alt="your image" />
在提交的php文件中:
if($_FILES["imgInp"]["name"]!='')
{
$first_file=rand().$_FILES["imgInp"]["name"];
$path="images/template/usersupload/";
$tot_dir=$path.$first_file;
if(file_exists($path))
{
move_uploaded_file($_FILES["imgInp"]["tmp_name"],$tot_dir);
}
}
else
{
echo '<script>alert("You forgot to upload a file!!!");
</script>';
echo'<script type="text/javascript">';
?>
window.location="index.php";
<?php
echo '</script>';
}
if($\u文件[“imgInp”][“name”]!=”)
{
$first_file=rand().$文件[“imgInp”][“name”];
$path=“images/template/usersupload/”;
$tot_dir=$path.$first_文件;
如果(文件_存在($path))
{
移动上传的文件($文件[“imgInp”][“tmp_名称”],$tot_dir);
}
}
其他的
{
echo'警报(“你忘了上传文件!!!”;
';
回声';
?>
window.location=“index.php”;
更改您提交Php代码的位置
您忘记在脚本标记中包装警报:)
if($\u文件[“imgInp”][“name”]!=”)
{
$first_file=rand().$文件[“imgInp”][“name”];
$path=“images/template/usersupload/”;
$tot_dir=$path.$first_文件;
如果(文件_存在($path))
{
移动上传的文件($文件[“imgInp”][“tmp_名称”],$tot_dir);
}
}
其他的
{
回声';
echo'警报(“你忘了上传文件!!!”;
setInterval(function(){window.location.href=“index.php”},5000);
';
回声';
}
?>
没有PHPalert@bub他在呼应一声jsalert@litelite我知道这一点,但标题是php alert不起作用检查开发控制台是否有错误这是我第一次使用php,我不知道什么是php以及如何使用开发控制台。请提供更多详细信息。提前谢谢。不幸的是,它不起作用即使在编辑之后。
if($_FILES["imgInp"]["name"]!='')
{
$first_file=rand().$_FILES["imgInp"]["name"];
$path="images/template/usersupload/";
$tot_dir=$path.$first_file;
if(file_exists($path))
{
move_uploaded_file($_FILES["imgInp"]["tmp_name"],$tot_dir);
}
}
else
{
echo'<script type="text/javascript">';
echo '<script>alert("You forgot to upload a file!!!");
setInterval(function(){window.location.href="index.php" },5000);
</script>';
echo '</script>';
}
?>