<?php
require_once "core/init.php";
if(isset($_FILES['file'])){
$file = $_FILES['file'];
// File properties
$file_name = $file['name'];
$file_tmp = $file['tmp_name'];
$file_size = $file['size'];
$file_error = $file['error'];
// Work out the file extension
$file_ext = explode('.', $file_name);
$file_ext = strtolower(end($file_ext));
$allowed = array('jpg', 'png');
if(in_array($file_ext, $allowed))
{
echo 'Your file will be processed shortly, thank you.';
}
if($file_error == true)
{
echo 'Failed to upload file';
}
if($file_size <= 2097152) {
$file_name_new = uniqid('', true) . '.' . $file_ext;
$file_destination = 'profilepictures/' . $file_name_new;
if(move_uploaded_file($file_tmp, $file_destination));
echo $destination;
}
}
?>
Simple problem, just frustrated at the moment. I'm trying to get it to echo Failed to upload file on a failed upload, but it's doing it on a successful upload and failed upload. I get both messages, the successful one and failed one on good uploads, but when it's a bad upload I only get the failed one.
$file_erroron a successful upload - see what it says?