Remotive
04-27-2012, 06:19 PM
Okay, I have made my form for an upload script I am making and the name of the file input is called 'file', so I assume this is what I am supposed to put when the form is submitted, I also have my form set to enctype="multipart/form-data" so I know that isn't the problem, which I have read is normally the culprit as to why it won't work.
Anyway here is my code...
$filename = $_FILES["file"]["name"];
$file_basename = substr($filename, 0, strripos($filename, '.')); // strip extention
$file_ext = substr($filename, strripos($filename, '.')); // strip name
$filesize = $_FILES["file"]["size"];
$title1 = $_POST['title'];
$title = addslashes($title1);
$link = $_POST['link'];
if (($file_ext == ".png" || $file_ext == ".gif") && ($filesize < 200000)) {
$newfilename = md5($file_basename) . $file_ext;
if (file_exists("images/" . $newfilename)) {
$error = "Unexpected error, we're working on this! Try again!";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], "images/" . $newfilename);
$SQL = "INSERT INTO `images` (`title`, `link`, `src`) VALUES ('$title', '$link', 'images/$newfilename')";
$result = mysql_query($SQL);
...the only error I am getting is this; "Notice: Undefined index: file in C:\xampp\htdocs\tomaldy\pages\add_image.php on line 9" and then the exact same for line 12.
I don't understand what is happening? I am not super-experienced in PHP so I understand if it's insanely obvious what's wrong.
Do I have to $_POST my 'file' at all? I'm so confused.
Any help is extremely appreciated as I'm sure you all know how much of a pain in the neck PHP can be sometimes... :P
Once again, thanks for any help!
Anyway here is my code...
$filename = $_FILES["file"]["name"];
$file_basename = substr($filename, 0, strripos($filename, '.')); // strip extention
$file_ext = substr($filename, strripos($filename, '.')); // strip name
$filesize = $_FILES["file"]["size"];
$title1 = $_POST['title'];
$title = addslashes($title1);
$link = $_POST['link'];
if (($file_ext == ".png" || $file_ext == ".gif") && ($filesize < 200000)) {
$newfilename = md5($file_basename) . $file_ext;
if (file_exists("images/" . $newfilename)) {
$error = "Unexpected error, we're working on this! Try again!";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], "images/" . $newfilename);
$SQL = "INSERT INTO `images` (`title`, `link`, `src`) VALUES ('$title', '$link', 'images/$newfilename')";
$result = mysql_query($SQL);
...the only error I am getting is this; "Notice: Undefined index: file in C:\xampp\htdocs\tomaldy\pages\add_image.php on line 9" and then the exact same for line 12.
I don't understand what is happening? I am not super-experienced in PHP so I understand if it's insanely obvious what's wrong.
Do I have to $_POST my 'file' at all? I'm so confused.
Any help is extremely appreciated as I'm sure you all know how much of a pain in the neck PHP can be sometimes... :P
Once again, thanks for any help!