I have a problem with my upload.php page. Form some reason it has stopped working. What I mean by that is it no longer posts to my database table (test). It returns no errors and I am able to echo out the post values from my form. That means the form is working properly so the problem must lie with how my page is handling the post data. I have no memory of modifying this page from the last time it was working. If anyone that is more proficient in PHP than I would be willing to take a look I would appreciate it.
//Image upload and error handling
// Access the $_FILES global variable for this specific file being uploaded
// and create local PHP variables from the $_FILES array of information
$fileName = $_FILES["uploaded_file"]["name"]; // The file name
$fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"]; // File in the PHP tmp folder
$fileType = $_FILES["uploaded_file"]["type"]; // The type of file it is
$fileSize = $_FILES["uploaded_file"]["size"]; // File size in bytes
$fileErrorMsg = $_FILES["uploaded_file"]["error"]; // 0 = false | 1 = true
$kaboom = explode(".", $fileName); // Split file name into an array using the dot
$fileExt = end($kaboom); // Now target the last array element to get the file extension
// START PHP Image Upload Error Handling --------------------------------------------------
if (!$fileTmpLoc) { // if file not chosen
echo "ERROR: Please browse for a file before clicking the upload button.";
exit();
} else if($fileSize > 5242880) { // if file size is larger than 5 Megabytes
echo "ERROR: Your file was larger than 5 Megabytes in size.";
unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
exit();
} else if (!preg_match("/.(gif|jpg|png)$/i", $fileName) ) {
// This condition is only if you wish to allow uploading of specific file types
echo "ERROR: Your image was not .gif, .jpg, or .png.";
unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
exit();
} else if ($fileErrorMsg == 1) { // if file upload error key is equal to 1
echo "ERROR: An error occured while processing the file. Try again.";
exit();
}
// END PHP Image Upload Error Handling ----------------------------------------------------
// Place it into your upload folder mow using the move_uploaded_file() function
$moveResult = move_uploaded_file($fileTmpLoc, "uploads/original/$fileName");
// Check to make sure the move result is true before continuing
if ($moveResult != true) {
echo "ERROR: File not uploaded. Try again.";
unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
exit();
}
//unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
// ---------- Include Adams Universal Image Resizing Function --------
include_once("ak_php_img_lib_1.0.php");
$target_file = "uploads/original/$fileName";
$resized_file = "uploads/resized_$fileName";
$wmax = 100;
$hmax = 350;
ak_img_resize($target_file, $resized_file, $wmax, $hmax, $fileExt);
// Run the function again with new parameter values
$newname = "uploads/original/$fileName";
$resized_file = "uploads/l_resized/$fileName";
$wmax = 400; // change sizes to new size
$hmax = 1000; // change sizes to new size
ak_img_resize($target_file, $resized_file, $wmax, $hmax, $fileExt);
// ----------- End Adams Universal Image Resizing Function -----------
// Display things to the page so you can see what is happening for testing purposes
/*echo "The file named <strong>$fileName</strong> uploaded successfuly.<br /><br />";
echo "It is <strong>$fileSize</strong> bytes in size.<br /><br />";
echo "It is an <strong>$fileType</strong> type of file.<br /><br />";
echo "The file extension is <strong>$fileExt</strong><br /><br />";
echo "The Error Message output for this upload is: $fileErrorMsg";*/
//mysql_close($con);
//header('Location: [url]http://localhost/Submitted_successfully.html');[/url]
}
?>
Are you sure you haven't modified it recently? I recall posting in the mysql forum for a PDO question you have on binding, and you are using the prepared statements here.
Does it successfully move the file to the uploads/original/$fileName location? Make sure you enable error reporting as well (in case you don't have PDO capability or valid mysql drivers for PDO):
Also, check the $result. If its true, it was successful, so you can then check the $query->rowCount(). I think that's right (Dormlich is the resident PDO expert )
Are you sure you haven't modified it recently? I recall posting in the mysql forum for a PDO question you have on binding, and you are using the prepared statements here.
Does it successfully move the file to the uploads/original/$fileName location? Make sure you enable error reporting as well (in case you don't have PDO capability or valid mysql drivers for PDO):
Also, check the $result. If its true, it was successful, so you can then check the $query->rowCount(). I think that's right (Dormlich is the resident PDO expert )
That question was for a different page. I had this one working a while before that. And no, it does not move the file anymore, do you see an error with it?
That question was for a different page. I had this one working a while before that. And no, it does not move the file anymore, do you see an error with it?
I have a Fatal error:
Quote:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'Email' cannot be null' in C:\xampp\htdocs\uploadPDO.php:44 Stack trace: #0 C:\xampp\htdocs\uploadPDO.php(44): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\uploadPDO.php on line 44
The usage looks right to me. The isset check verifies that you have an email option, and it extracts from the same.
Check your HTML form that it creates. The only thing I can think of with this is that you have 2x input types named email, the second of which is the one that will win. Of course, this assumes that you have actually filled out the form since you need to do that as well.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
Extra commas usually don't matter in arrays, but I could see it being a problem when passed to an external resource like a prepared statement. The error doesn't really clarify (where's Dorm :P).
Extra commas usually don't matter in arrays, but I could see it being a problem when passed to an external resource like a prepared statement. The error doesn't really clarify (where's Dorm :P).
It wasn't the comma. I've since gotten it to work. It had something to do with the isset function.
Lols, that makes *no* sense at all. It shouldn't matter if its $_POST['Email'] or $Email since both are in scope here. Sometimes you cannot use an array for a few things, such as for a reference, but its usually that way where arrays are no good and must be a variable (regardless of using other references to use a variable within an array).
Try changing that back to just $Email. Does that still work?
Lols, that makes *no* sense at all. It shouldn't matter if its $_POST['Email'] or $Email since both are in scope here. Sometimes you cannot use an array for a few things, such as for a reference, but its usually that way where arrays are no good and must be a variable (regardless of using other references to use a variable within an array).
Try changing that back to just $Email. Does that still work?
I think changing it back worked because the syntax of my isset function was wrong. Using $Email worked just now, but only after changing the isset.
You have been alternating between a variable named $Image and one called $filePath. At one point (in your first code) you assign $filePath a new value, but then revert to using $Image.
I don't know whether this is an issue but it is worth checking and revising if appropriate.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
You have been alternating between a variable named $Image and one called $filePath. At one point (in your first code) you assign $filePath a new value, but then revert to using $Image.
I don't know whether this is an issue but it is worth checking and revising if appropriate.
I do think you are correct. I took $Image out of the isset funtion and set: