1 回答
TA贡献1828条经验 获得超3个赞
两件事,一是路径不是动态的,我做到了,二是确保value="<?php echo $a;?>"具有“fesectionatimetable”的值。
<?php
if(isset($_POST["submit"]))
{
$a= $_POST['a'] ;
if ($a == 'fesectionatimetable'){
$target_dir = "content/"; //your path
$old_files = glob('content/*');
foreach($old_files as $file){ // iterate files
if(is_file($file))
unlink($file); // delete file
}
}
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been
uploaded.";
}
}
?>
<html>
<body>
<form action="index.php" method="post" enctype="multipart/form-data">
<h2 style = "color : black ; "> Select image to upload: </h2>
<h6 style = "color : black ; "> <input type="file" name="fileToUpload" id="fileToUpload">
</h6>
<h6 style = "color : black ; "> <input class="btn btn-primary" href="#" role="button"
type="submit" value="Upload Image" name="submit"> </h6>
<input type="text" name='a' value="fesectionatimetable" style="display:none"> //your value
</form>
</body>
<html>
- 1 回答
- 0 关注
- 83 浏览
添加回答
举报