Jump to content

Uploading a photo with out refreshing page


xcandiottix

Recommended Posts

I'm having trouble getting this to work and I'm starting to wonder if it's possible or not. Basically I want someone to navigate to a "Homepage" which has 5 blank table cells. If the user has uploaded an image previously, a thumbnail of the image will be loaded into one of the 5 cells. If the user has not uploaded an image, then a submit field will be present in the table cell.

 

[(thumbnail of image1)][(thumnail of image 2)][browse for a file ____________ SUBMIT][etc][etc]

 

When the user clicks 'browse'  and chooses an image then clicks submit I would like the file to be uploaded, then the image thumbnail shown. So far, I can get the file to upload to php's temp location but the file will not end up in its final destination. Any thoughts?

 

<?php

$userID = $_COOKIE['user'];

$con = mysql_connect("com","UN","PW");

mysql_select_db("rmvusers", $con);

$sql = "SELECT * FROM rmvusers WHERE db_Id = '$userID'";

$result = mysql_query($sql);

        $row = mysql_fetch_assoc($result);

echo '<table width="200" border="1" align="center" valign="top">

  <tr>

    <td>';

if($row['db_File1']){

echo "yes file";

}

else{

echo '

<form method="post"

enctype="multipart/form-data"">

      <p class="default">

      <br />

        Title of Image<br />

        <input name="Title" type="text" size="37" maxlength="20" /><br>

        <label for="file">Select  photo to upload.</label>

        <br>

        <input name="file" type="file" id="file" size="20"/>

        <br><input type="submit" name="Submit" value="Submit"/></p>

    </form>

';

$con = mysql_connect(".com","UN","PW");

mysql_select_db("rmvusers", $con);

 

if ((($_FILES["file"]["type"] == "image/gif")

|| ($_FILES["file"]["type"] == "image/jpeg")

|| ($_FILES["file"]["type"] == "image/pjpeg"))

&& ($_FILES["file"]["size"] < 200000))

  {

  if ($_FILES["file"]["error"] > 0)

    {

    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";

echo "This file is either not a gif / jpeg or its size exceedes our upload limit. Please try again.";

    }

  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. ";

  echo "<br>";

  echo "Please rename this file and try again.";

      }

    else

      {

      move_uploaded_file($_FILES["file"]["tmp_name"],

      "upload/" . $_FILES["file"]["name"]);

      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];

  $var1=$_FILES["file"]["name"];

  $var2=0;

  $var3=getenv("REMOTE_ADDR");

 

          $string = $var3;

          $new_string = ereg_replace("[.]", "", $string);

          $var3 = $new_string;

  $sql="INSERT INTO rmvusers (db_File1)

VALUES

('$var1')";

      }

    }

  }

else

  {

  echo "Invalid file, check size, name, and that file type is either gif or jpg then try again.";

  }

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

 

 

Again, right now my DB won't update that a file has been uploaded. Also, the file does not show up in my 'upload' folder even though the file does upload .. i believe it is getting stuck in the php temp folder.

 

Okay an update.

 

I have the photos uploading correctly now and they end up in the correct folder. Also, the database is updated that an image exists. BUT the database is going down to the next user in the database and updating that line with the uploaded photo. This may have something to do with my log in script.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.