Wandbox
SettingsLog
SettingsLog
Language
GitHubLogin
Ran/Viewed Log

single-input.php

Language

PHP

Compiler

php 8.2.1

Options

single-input.php

noname

$ php prog.php
<form method="post">
<div class="image-partial">
<h2>動画・画像をアップロード(Upload video・image)<span class="required">※ファイルサイズ15MB以内、JPG/GIF/PNG/MP4</span></h2>
<div class="image-selector-button">
<label>
<div class="image-camera-icon">
<img src="
Warning: Undefined variable $camera_url in /home/jail/prog.php on line 7
" style="height: 100px;">
</div>
<input type="file" class="attach" name="attach[]" accept=".png, .jpg, .jpeg, .pdf, .mp4" style="display: none;">
</label>
<input type="hidden" class="attachdel" name="attachdel[]">
<button type="button" class="attachclear">clear</button>
<div class="viewer">
Warning: Undefined variable $attach in /home/jail/prog.php on line 13

Warning: Trying to access array offset on value of type null in /home/jail/prog.php on line 13
</div>
</div>
<div class="image-selector-button">
<label>
<div class="image-camera-icon">
<img src="
Warning: Undefined variable $camera_url in /home/jail/prog.php on line 18
" style="height: 100px;">
</div>
<input type="file" class="attach" name="attach[]" accept=".png, .jpg, .jpeg, .pdf, .mp4" style="display: none;">
</label>
<input type="hidden" class="attachdel" name="attachdel[]">
<button type="button" class="attachclear">clear</button>
<div class="viewer">
Warning: Undefined variable $attach in /home/jail/prog.php on line 24

Warning: Trying to access array offset on value of type null in /home/jail/prog.php on line 24
</div>
</div>
</div>
</form>

<script>
const attach = document.querySelectorAll('.attach');
const del = document.querySelectorAll('.attachdel');
const clear = document.querySelectorAll('.attachclear');
const viewer = document.querySelectorAll('.viewer');
for (let i = 0; i < attach.length; i++) {
attach[i].addEventListener('change', () => {
if (attach[i].files[0].size > 15 * 1024 * 1024) {
alert('ファイルサイズが 15MBバイトを超えています');
return;
}
del[i].value = "";
viewer[i].innerHTML = "";
if (attach[i].files.length !== 0) {
const reader = new FileReader();
reader.onload = () => {
var child = null;
if (reader.result.indexOf("data:image/jpeg;base64,") === 0 ||
reader.result.indexOf("data:image/png;base64,") === 0) {
child = document.createElement("img");
} else if (reader.result.indexOf("data:video/mp4;base64,") === 0) {
child = document.createElement("video");
child.setAttribute("controls", null);
} else if (reader.result.indexOf("data:application/pdf;base64,") === 0) {
child = document.createElement("iframe");
} else {
alert("対象外のファイルです");
alert(reader.result);
attach[i].value = "";
}
if (child !== null) {
child.style.height = "100px";
child.src = reader.result;
viewer[i].appendChild(child);
}
};
reader.readAsDataURL(attach[i].files[0]);
}
});
clear[i].addEventListener('click', () => {
attach[i].value = "";
del[i].value = "1";
viewer[i].innerHTML = "";
});
}
<script>
Exit Code:
0