I am developing a Library Management System. An admin side is allowed to enter a new book. I am wondering if it is possible to auto-select a file to upload if the admin leaves it empty?
I used the following html code (among other input) for the form.
<input name="MAX_FILE_SIZE" value="102400" type="hidden">
<input name="image" accept="image/jpeg" type="file">
In the php file that processes the input, I used the following code to upload the file.
$fileName = $_FILES['image']['name'];
$tmpName = $_FILES['image']['tmp_name'];
$fileSize = $_FILES['image']['size'];
$fileType = $_FILES['image']['type'];
$filePath = $uploadDir . $fileName;
$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading file";
exit;
}
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
The code works perfectly fine. I am just wondering if there is a way to auto-select a default image if the admin leaves the file uploader empty. The image (containing the text "IMAGE NOT AVAILABLE") is already pre-saved on the folder where all uploaded images are saved. How do I select this before saving it to my database?
CHEERS!
You should check if file uploaded to server using is_uploaded_file
function. If not, just save the path of your default no-image.gif
or something similar.