I have a basic form to upload an image:
<?php
if(!empty($_POST['?upload_img'])) {
echo "true<br>";
} else { echo "false<br>"; }
?>
<html>
<form action='' method='post' enctype='multipart/form-data'>
<input type='file' name='input_img' id='input_img'><br>
<input type='submit' value='Upload Image' name='?upload_img'>
</form>
</html>
I would like a PHP boolean/evaluation pair to run only once for each upload.
I have tried evaluating using !empty
,isset
,sizeof(foo)>0
I have also tried to find a solution using $_SESSION
s
Is there are correct use of unset
or $_POST=array()
/$_FILE=array()
that I have missed?
I can achieve the desired behaviour with sessions:
<?php
session_start();
if(!empty($_SESSION['foo'])) {
echo "true<br>";
} else { echo "false<br>"; }
?>
<html>
<?php
if(!sizeof($_SESSION['foo'])) {
$_SESSION['foo']=array();
$_SESSION['foo']['bar']="path/to/the/file.png";
} else { $_SESSION=array(); }
?>
</html>
How can I achieve the same with input from a <form>
instead?
Any help is much appreciated!