PHP/MsSQL Image Upload

Ok, still stuck on PHP/MsSQL. After this project is over I will hopefull never have tp use this combo again.

Ive got everything else working so far and now I am onto the next stage which is adding image upload. Just want to webcame a quick shot of the visitor to use on their ID we will print up. First step is just to get the image o upload to a file folder on the webserver, My code will let meinsert a visitor and all their data, but the image upload is not sending the image to the specified file folder and it is not throwing an error. Any help with this would be gratly appreciated.

[php]
$name = $_FILES[‘myfile’][‘name’];
$type = $_FILES[‘myfile’][‘type’];
$size = $_FILES[‘myfile’][‘size’];
$temp = $_FILES[‘myfile’][‘tmp_name’];
$error = $_FILES[‘myfile’][‘error’];

	if ($error > 0)
		{
			die ("Error uploading image, Error code $error.");
		}
		
	else
		{
		move_uploaded_file ($temp,"images/visitors/".$name);
		}[/php]

Sorry about that last post. I really messed that up. Same problem for the most part though. But when I hit submit I get this error:

Array ( [0] => 42S22 [SQLSTATE] => 42S22 [1] => 207 [code] => 207 [2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Invalid column name ‘front’. [message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Invalid column name ‘front’. ) )

but front is a column in the DB.

[php]
var _debug = false;
var _placeholderSupport = function() {
var t = document.createElement(“input”);
t.type = “text”;
return (typeof t.placeholder !== “undefined”);
}();

window.onload = function() {
var arrInputs = document.getElementsByTagName(“input”);
for (var i = 0; i < arrInputs.length; i++) {
var curInput = arrInputs[i];
if (!curInput.type || curInput.type == “” || curInput.type == “text”)
HandlePlaceholder(curInput);
else if (curInput.type == “password”)
ReplaceWithText(curInput);
}

if (!_placeholderSupport) {
    for (var i = 0; i < document.forms.length; i++) {
        var oForm = document.forms[i];
        if (oForm.attachEvent) {
            oForm.attachEvent("onsubmit", function() {
                PlaceholderFormSubmit(oForm);
            });
        }
        else if (oForm.addEventListener)
            oForm.addEventListener("submit", function() {
                PlaceholderFormSubmit(oForm);
            }, false);
    }
}

};

function PlaceholderFormSubmit(oForm) {
for (var i = 0; i < oForm.elements.length; i++) {
var curElement = oForm.elements[i];
HandlePlaceholderItemSubmit(curElement);
}
}

function HandlePlaceholderItemSubmit(element) {
if (element.name) {
var curPlaceholder = element.getAttribute(“placeholder”);
if (curPlaceholder && curPlaceholder.length > 0 && element.value === curPlaceholder) {
element.value = “”;
window.setTimeout(function() {
element.value = curPlaceholder;
}, 100);
}
}
}

function ReplaceWithText(oPasswordTextbox) {
if (_placeholderSupport)
return;
var oTextbox = document.createElement(“input”);
oTextbox.type = “text”;
oTextbox.id = oPasswordTextbox.id;
oTextbox.name = oPasswordTextbox.name;
//oTextbox.style = oPasswordTextbox.style;
oTextbox.className = oPasswordTextbox.className;
for (var i = 0; i < oPasswordTextbox.attributes.length; i++) {
var curName = oPasswordTextbox.attributes.item(i).nodeName;
var curValue = oPasswordTextbox.attributes.item(i).nodeValue;
if (curName !== “type” && curName !== “name”) {
oTextbox.setAttribute(curName, curValue);
}
}
oTextbox.originalTextbox = oPasswordTextbox;
oPasswordTextbox.parentNode.replaceChild(oTextbox, oPasswordTextbox);
HandlePlaceholder(oTextbox);
if (!_placeholderSupport) {
oPasswordTextbox.onblur = function() {
if (this.dummyTextbox && this.value.length === 0) {
this.parentNode.replaceChild(this.dummyTextbox, this);
}
};
}
}

function HandlePlaceholder(oTextbox) {
if (!_placeholderSupport) {
var curPlaceholder = oTextbox.getAttribute(“placeholder”);
if (curPlaceholder && curPlaceholder.length > 0) {
Debug(“Placeholder found for input box '” + oTextbox.name + "’: " + curPlaceholder);
oTextbox.value = curPlaceholder;
oTextbox.setAttribute(“old_color”, oTextbox.style.color);
oTextbox.style.color = “#c0c0c0”;
oTextbox.onfocus = function() {
var _this = this;
if (this.originalTextbox) {
_this = this.originalTextbox;
_this.dummyTextbox = this;
this.parentNode.replaceChild(this.originalTextbox, this);
_this.focus();
}
Debug(“input box '” + _this.name + “’ focus”);
_this.style.color = _this.getAttribute(“old_color”);
if (_this.value === curPlaceholder)
_this.value = “”;
};
oTextbox.onblur = function() {
var _this = this;
Debug(“input box '” + _this.name + “’ blur”);
if (_this.value === “”) {
_this.style.color = “#c0c0c0”;
_this.value = curPlaceholder;
}
};
}
else {
Debug(“input box '” + oTextbox.name + “’ does not have placeholder attribute”);
}
}
else {
Debug(“browser has native support for placeholder”);
}
}

function Debug(msg) {
if (typeof _debug !== “undefined” && _debug) {
var oConsole = document.getElementById(“Console”);
if (!oConsole) {
oConsole = document.createElement(“div”);
oConsole.id = “Console”;
document.body.appendChild(oConsole);
}
oConsole.innerHTML += msg + “
”;
}
}
</script

<?php include 'includes/db/connect.php'; error_reporting(E_ALL); ini_set("display_errors", "on"); if (isset($_POST['Visitor_Name_Prefix'])) { if(is_uploaded_file($_FILES['front']['tmp_name'])) { $name = $_FILES['front']['name']; $tmp_name = $_FILES['front']['tmp_name']; $location = "front/$name"; move_uploaded_file($tmp_name,$location); } else{$location = 'front/default.jpg';} $aAllowed = array( 'Visitor_Name_Prefix', 'Visitor_Name_First', 'Visitor_Name_Middle', 'Visitor_Name_Last', 'Visitor_Name_Suffix', 'front', 'Visitor_Agency', 'local_history', 'Visitor_ID_Type', 'Visitor_ID_Issue_Agency', 'Visitor_ID_Number', 'Surrendered_Own_ID', 'Spd_ID_Number', 'Date_Of_Visit', 'Purpose_Of_Visit', 'Time_Of_Visit', 'Individual_Visit_Department', 'Individual_Visit_Name_Prefix', 'Individual_Visit_Name_First', 'Individual_Visit_Name_Last', 'Escort_Status', ); // all the allowed items. function removeUnknowns(&$item, $key, array $aAllowed) { if (!in_array($key, $aAllowed)) { $item = ""; } } $aSubmitted = $_POST; array_walk($aSubmitted, 'removeUnknowns', $aAllowed); $aSubmitted = array_filter($aSubmitted); $sFields = implode('], [', array_keys($aSubmitted)); $sReplacement = rtrim(str_repeat('?, ', count($aSubmitted)), ', '); $sQry = "INSERT INTO [VisitorLog] ([$sFields]) VALUES ($sReplacement)"; if (false === ($stmt = sqlsrv_query($conn, $sQry, array_values($aSubmitted)))) { die(print_r(sqlsrv_errors(), true)); } } ?> <?php if (isset($_GET['submit_msg'])) { echo "

"; echo $_GET['submit_msg']; echo "

"; } ?> <?php include 'includes/head/head_main.php'; ?>
<?php include 'includes/header/header_main.php'; ?>

SPD: Visitor Check In

Visitor Personal Information

Prefix:
Mr. Mrs Miss Dr. Det. Ptlm. Ptlw. Cpl. SrCpl. Sgt. MSgt. Lt. Capt. Maj. Col. Chief.
First Name:

Middile Name:

Last Name:

Suffix:
Sr Jr III IV V
Visitor Agency:

History:
Yes No
Visitor Picture:

Visitor ID Information

Type:

Issuing Agency:

Number:

ID Surrendered:
Yes No
Escort Status:
Escorted Un-Escorted
SPD ID Number:
01 02 03 04 05 06 07 08 09 10

Visit Information

Date:

Purpose:
Interview Board Interview Criminal Testing Polygraph Fingerprints Scheduled Meeting Scrap Metal Background Check Employment Visitor Other
Check In Time:

Visted Department:

Visited Prefix:

Visited First Name:

Visited Last Name:


[/php][/code]

Does the error not tell you the problem?

“Invalid column name ‘front’”

Yes, the error does say that. But the column name is ‘front’ spelling is right, everything is right but it is still throwing that error.

I wish I could help but I’m just not familiar with MSSQL

I don’t know if this will help, but the following will move it to a folder. Then all you would have to do is store the name in the My_SQL database. Then just reference the folder location and file_name.

[php] $allowedExts = array(“jpg”, “jpeg”, “gif”, “png”);
$basenameAndExtension = explode(’.’, $_FILES[“file”][“name”]);
$extension = end($basenameAndExtension);

   if ((($_FILES["file"]["type"] == "image/gif")
   || ($_FILES["file"]["type"] == "image/jpeg")
   || ($_FILES["file"]["type"] == "image/png")
   || ($_FILES["file"]["type"] == "image/pjpeg"))
   && ($_FILES["file"]["size"] < 800000)
   && in_array($extension, $allowedExts))
	{
	if ($_FILES["file"]["error"] > 0)
	  {
	  echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
	  }
	else
	  {
	  echo "Upload: " . $_FILES["file"]["name"] . "<br>";
	  echo "Type: " . $_FILES["file"]["type"] . "<br>";
	  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
	  echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
   
	  if (file_exists("upload/" . $_FILES["file"]["name"]))
	    {
	    echo $_FILES["file"]["name"] . " already exists. ";
	    }
	  else
	    {
	    move_uploaded_file($_FILES["file"]["tmp_name"],
	    "upload/" . $_FILES["file"]["name"]);
	    echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
	    $image_name = $_FILES["file"]["name"];
	    echo "<br />";
	    echo "<img src=\"http://localhost/php_test/greencay_php/upload/" . $image_name . "\" alt=\"There ya go\" />";
	    echo "<br />";
	    }
	  }
	}
   else
	{
	echo "Invalid file";
	}[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service