Jump to content
Larry Ullman's Book Forums

knowledge

Members
  • Posts

    2
  • Joined

  • Last visited

  • Days Won

    1

knowledge last won the day on March 18 2014

knowledge had the most liked content!

knowledge's Achievements

Newbie

Newbie (1/14)

1

Reputation

  1. Found the error! You defined the extension with $file_ext like so: $file_ext = substr($file['name'], -4); if ( !in_array($file_type, $allowed_mime) || !in_array($file_ext, $allowed_extensions) ) { $add_product_errors['image'] = 'The uploaded file was not of the proper type.'; } just changed to: $ext = substr($file['name'], -4); if ( !in_array($file_type, $allowed_mime) || !in_array($ext, $allowed_extensions) ) { $add_product_errors['image'] = 'The uploaded file was not of the proper type.'; } works like a charm!
  2. 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']); } }
×
×
  • Create New...