Я пытаюсь использовать следующий скрипт для перенаправления, но он выполняется, а затем зависает перед перенаправлением. Непосредственно перед HTML у меня есть команда header ().
<code> <?php
require("../../../../wp-load.php");
if(isset($_POST['submit'])){
$file = $_FILES['file'];
$fileName = $file['name'];
$fileType = $file['type'];
$fileTmpLocation = $file['tmp_name'];
$fileSize = $file['size'];
$fileError = $file['error'];
if(($_POST['link']==='') && $_FILES['file']['name']===''){
unset($_POST);
unset($_FILES);
echo '<script language="javascript">';
echo 'alert("You must specify either a link or a file to upload")';
echo '</script>';
}
if ($_FILES['file']['name']!='' && $fileError !== 0){
unset($_POST);
unset($_FILES);
echo '<script language="javascript">';
echo 'alert("There was an error uploading your file, try again")';
echo '</script>';
}
if ($fileSize >500000){
unset($_POST);
unset($_FILES);
echo '<script language="javascript">';
echo 'alert("Your file is too large. Please limit file size to 5MB")';
echo '</script>';
}
$name = explode('.',$fileName);
if($_FILES['file']['name']!='' && count($name)!= 2){
echo '<script language="javascript">';
echo 'alert("File names must be in form fileName.fileType only 1 . allowed")';
echo '</script>';
}
$fileNameSave = uniqid($name[0].'_',true).'.'.$name[1];
$pos = strpos($fileNameSave, '.');
if ($pos !== false) {
$fileNameSave = substr_replace($fileNameSave, '', $pos, strlen('.'));
}
move_uploaded_file($fileTmpLocation,"../uploads/".$fileNameSave);
unset($_POST);
header("Location: https://www.sustainablewestonma.org/update.php");
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Update ITN</title>
<style>#d1{text-align:center;}#d3{width:30vw;margin:0 auto;}</style>
</head>
<body>
<div id='d1'>
<h1>SustainableWestonMA.org</h1>
<h2>In-The-News</h2>
</div>
<div id='d3'>
<form action="update_itn.php" method="POST" enctype="multipart/form-data">
<pre>
Date: <input type="date" name="date" id="date" class="date" /><br>
Event: <input type="text" name="event" id="event" /><br>
Link: <input type="text" name="link" id="link"/><br>
or File: <input type="file" name="file" id="file"/><br>
<button type="submit" name="submit" id="submit">Update</button>
In the example below:
October 7, 2019 Survey finds 292 gas leaks in Weston
https://weston.wickedlocal.com/news/20191007/survey-finds-292-gas-leaks-in-weston
date = October 7, 2019
Event = Survey finds 292 gas leaks in Weston
Link = https://weston.wickedlocal.com/news/20191007/survey-finds-292-gas-leaks-in-weston
You must specify a link or a file you want to link to but NOT both. File uploads are limited to 5MB