Please help me check this too. It works fine if I upload image but if I omit image, it doesn’t work and show me this error message: Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in… What could be wrong?
if (isset($_POST['button']) && $_POST['button'] == 'add')
{
// Bail out if the file isn't really an upload
if (!is_uploaded_file($_FILES['logo']['tmp_name']))
{
$error[] = 'There was no file uploaded!';
}
$uploadfile = filter_var($_FILES['logo']['tmp_name'], FILTER_SANITIZE_STRING);
$uploadname = filter_var($_FILES['logo']['name'], FILTER_SANITIZE_STRING);
$uploadtype = filter_var($_FILES['logo']['type'], FILTER_SANITIZE_STRING);
$uploadsize = filter_var($_FILES['logo']['size'], FILTER_SANITIZE_STRING);
$uploaddata = file_get_contents($uploadfile);
$maxsize = 102400;
if($uploadsize > $maxsize) {
$error[] = "The file you're trying to upload is bigger than approved 1 MB.";
}
if(empty($missing) && empty($error))
{
$conn = DatabaseManager::getConnection();
try
{
$sql = "INSERT INTO jobseekers (website, filename, mimetype, filedata, userName)
VALUES (:website, :filename, :mimetype, :filedata, :userName)";
$s = $conn->prepare($sql);
$s->bindValue(':website', $website);
$s->bindValue(':filename', $uploadname);
$s->bindValue(':mimetype', $uploadtype);
$s->bindValue(':filedata', $uploaddata);
$s->bindValue(':username', $username);
$s->execute();
$conn = null;
}
catch (PDOException $e)
{
$error[] = 'There is a problem, Please try again later.';
}
if($s->rowCount() == 1)
{
$formProcessed = true;
}
else
{
$error[] = "Unable to add new job application to the database.";
}
}
}
if ($formProcessed) {
$_SESSION['success'] = 'The info has been successfully added to the database.';
header('Location: ../status/');
exit();
}