У меня есть форма на моей странице с одним продуктом для отправки изображения с заказом. когда кнопка нажата, предполагается загрузить изображение, однако он перемещается на страницу, не найденную на странице. это то, что он выглядит следующим образом:Как я могу остановить кнопку отправки с меняющейся страницы?
function add_checkout_notice() {
echo '<form action="accept-file.php" method="POST" enctype="multipart/form-data">';
echo '<input type="file" name="photo[]" id="photoUpload" />';
echo '<input type="submit" name="submitPhoto" value="Submit">';
//echo '<input type="text" name="test_field" value="stuff">';
echo '</form>';
}
add_action('woocommerce_single_product_summary', 'add_checkout_notice');
Код в Accept-файл выглядит следующим образом:
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["photo"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$testLog = fopen(plugin_dir_path(__FILE__)."log.txt","w") or exit ("Unable to open file!");
fwrite ($testLog ,pathinfo($target_file,PATHINFO_EXTENSION));
fwrite ($testLog ,$_FILES["photo"]["name"]);
fwrite ($testLog ,$target_dir);
// Check if image file is a actual image or fake image
if(isset($_POST["submitPhoto"])) {
fwrite ($testLog ,"set");
$check = getimagesize($_FILES["photo"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
fwrite ($testLog ,"is image");
$uploadOk = 1;
} else {
echo "File is not an image.";
fwrite ($testLog ,"not an image");
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
fwrite ($testLog ,"already exists");
$uploadOk = 0;
}
любые советы?