Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    uploading image to server and data to database

    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);

    }
    ?>

  • #2
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    PHP Code:
    $target_path "C:\photos\ "
    Try changing to:

    PHP Code:
    $target_path "C:/photos/ "
    Leonard Whistler

  • #3
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Len Whistler
    PHP Code:
    $target_path "C:\photos\ "
    Try changing to:

    PHP Code:
    $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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •