After trying to add a product to the DB, I get an error saying there is an undefined variable (ext) in the add products script. Below is the lines where it is used:
$new_name .= ((substr($ext, 0, 1) != '.') ? ".{$ext}" : $ext);
Here is the whole IF statement:
if (!array_key_exists('image', $add_product_errors)) {
$new_name = sha1($file['name'] . uniqid('',true));
$new_name .= ((substr($ext, 0, 1) != '.') ? ".{$ext}" : $ext);
$dest = "../products/$new_name";
if (move_uploaded_file($file['tmp_name'], $dest)) {
$_SESSION['image']['new_name'] = $new_name;
$_SESSION['image']['file_name'] = $file['name'];
echo '<h4>The file has been uploaded!</h4>';
} else {
trigger_error('The file could not be moved.');
unlink ($file['tmp_name']);
}
}
My question is should this be declared as empty? Basically declaring it like this:
if (!array_key_exists('image', $add_product_errors)) {
$ext = ' ';
$new_name = sha1($file['name'] . uniqid('',true));
$new_name .= ((substr($ext, 0, 1) != '.') ? ".{$ext}" : $ext);
$dest = "../products/$new_name";
if (move_uploaded_file($file['tmp_name'], $dest)) {
$_SESSION['image']['new_name'] = $new_name;
$_SESSION['image']['file_name'] = $file['name'];
echo '<h4>The file has been uploaded!</h4>';
} else {
trigger_error('The file could not be moved.');
unlink ($file['tmp_name']);
}
}