...

View Full Version : uploading image to server and data to database



kevdoug
08-13-2006, 07:12 PM
Hi I am trying to upload an image to the server and at the same time add data to the database. I am have tryed various ways to do it I can achieve both seperateley but when I try to combine them it just won't have it. I have posted the two files below. The data is uploaded to the database but the image is not uploaded onto the server.


addimage.php
<form enctype="multipart/form-data" name="add" action="addimageupdate.php" method="post">

<!-- display field for user input //-->
<table>
<tr>
<td valign = "top"><strong>User Name:</strong></td>
<td>
<?php

$usrname = $_COOKIE[user_cookie];

echo "<strong>$usrname</strong>";

$conn = OCILogon("kevin", "kevin", "") or die ("connection failed");// make a connection to the database
$stmt = OCIParse($conn, "select distinct user_name from user_id where user_name = '$usrname' ");
OCIExecute($stmt);

OCIFetch($stmt);
?>

<input type='hidden' name='user_name' value='<?php echo OCIResult($stmt, 'USER_NAME'); ?>' />

<?php
OCIFreeStatement($stmt);
OCILogoff($conn);
?>
</td>
</tr>

<tr>
<td><strong>Album Name:</strong></td>
<td>
<select name = "album_name" onchange="document.album.submit()">
<?php
$usrname = $_COOKIE[user_cookie];

$conn = OCILogon("kevin", "kevin", "") or die ("connection failed");

$stmt = OCIParse($conn, "select * from album where user_name = '$usrname' ");

OCIExecute($stmt);
echo "Executed";

while (OCIFetch($stmt))
{
$record =OCIResult($stmt, 'ALBUM_NAME');
echo " <option value = '$record'> $record</option>";

}
OCIFreeStatement($stmt);
OCILogoff($conn);
?>
</select>
</td>
</tr>

<tr>
<td valign = "top"><strong>Photo Name:</strong></td>
<td valign = "top"><input name ="photo_name" type="text" size="30" /></td><br /><br />
</tr>

<input type="hidden" name="MAX_FILE_SIZE" value="100000000000" />
<tr>
<td><strong>Photo Location:</strong></td>
<td valign = "top"><input name="uploadedfile" type="file" size="30" /><br /></td><br /><br />
<td>
</td>
</tr>

<tr>
<td><strong>Keyword One:</strong></td>
<td valign = "top"><input name ="keyone" type="text" size="30" /></td><br /><br />
<td>
</td>
</tr>

<tr>
<td><strong>Keyword Two:</strong></td>
<td valign = "top"><input name ="keytwo" type="text" size="30" /></td><br /><br />
<td>
</td>
</tr>

<tr>
<td><strong>Keyword Three:</strong></td>
<td valign = "top"><input name ="keythree" type="text" size="30" /></td><br /><br />
<td>
</td>
</tr>

<tr>
<td valign = "top"><input type="submit" name="submit" value="Add new photo"></td>
</tr>

</table>
</form>

addimageupdate.php
<?php
// Where the file is going to be placed
$target_path = "C:\photos\ ";

/* Add the original filename to our target path. */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}

else
{
echo "There was an error uploading the file, please try again!";
}
?>

<?php
$conn = OCILogon("kevin", "kevin", "") or die ("connection failed");// make a connection to the database
$user = $_POST['user_name'];
$album_name = $_POST['album_name'];
$photo_name = $_POST['photo_name'];
$image_loc = $_POST['uploadedfile'];
$date = date("d M Y");
$key1 = $_POST['keyone'];
$key2 = $_POST['keytwo'];
$key3 = $_POST['keythree'];

$user = strtoupper($user);
$album_name = strtoupper( $album_name);
$photo_name = strtoupper($photo_name);
$key1 = strtoupper($key1);
$key2 = strtoupper($key2);
$key3 = strtoupper($key3);

{
$sql = "insert into photo (user_name, album_name, photo_name, photo_location, photo_date, keyword_one, keyword_two, keyword_three)";
$sql .= " values('$user', '$album_name', '$photo_name', '$image_loc', '$date', '$key1', '$key2', '$key3')";

echo $sql;
$stmt = OCIParse($conn, $sql) or die ("Insertion failed");

//OCIExecute($stmt);
$add = OCIExecute($stmt);

if ($add)
{
echo "<h1>New Image added to album $album_name</h1>";

}
else
{

echo "<h1>Adding image failed please try again<br /> Please make sure all field are completed.</h1>";
}

// Commit to save changes...
OCICommit($conn);

//free memory
OCIFreeStatement($stmt);

// Logoff from Oracle...
OCILogoff($conn);

}
?>

Len Whistler
08-13-2006, 08:50 PM
$target_path = "C:\photos\ ";

Try changing to:


$target_path = "C:/photos/ ";

kevdoug
08-14-2006, 03:40 PM
$target_path = "C:\photos\ ";

Try changing to:


$target_path = "C:/photos/ ";


Thanks that wasn't the problem but it helped to sort out another problem i was having with white spaces.

I have sorted it out now thanks it was just simplt renaming the variable.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum