image uploading and display to the profile member

Discussion in 'PHP' started by tldmic, Feb 21, 2010.

  1. #1
    HI all,

    Here I am again,trying to understand the error in the follwing code as an armature. Well, thus far my coding to build my own web is going well except the hand brake of uploading the images into my profile members.
    What I am trying to achieve is when my friends are logged in,they sould be able to update their profile by uploading their photo into their profile page.
    Thus far,the program can save the name of the image,but it gives errors when writting the photo into the server,can anyone help me with this problem?

    many thanks
    tldmic

    <?php

    //This is the directory where images will be saved
    $target = "c:/upload/";
    $target = $target . basename( $_FILES['photo']['name']);

    //This gets all the other information from the form
    $name=$_POST['name'];
    $email=$_POST['email'];
    $phone=$_POST['phone'];
    $pic=($_FILES['photo']['name']);

    // Connects to your Database
    $server = "localhost"; // this is the server address and port
    $username = "root"; // change this to your mysql username
    $password = "mike"; // change this to your mysql password

    $link = mysql_connect ($server, $username, $password)
    or die ("could not connect");

    mysql_select_db("upload") or die(mysql_error()) ;

    //Writes the information to the database
    mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ;

    //Writes the photo to the server
    if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/pjpeg"))
    && ($_FILES["file"]["size"] < 524288))
    {
    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("C:/upload" . $_FILES["file"]["name"]))
    {
    echo $_FILES["file"]["name"] . " already exists. ";
    }
    else
    {
    move_uploaded_file($_FILES["file"]["tmp_name"],
    "images/" . $_FILES["file"]["name"]);
    echo "Stored in: " . "C:/upload" . $_FILES["file"]["name"];
    }
    }
    }
    else
    {
    echo "Invalid file";
    }
    ?>
     
    tldmic, Feb 21, 2010 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    what does it say?
    do you have set 0777 rights?
     
    crivion, Feb 21, 2010 IP
  3. tldmic

    tldmic Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hi

    as you can seee that it echos "invalid file',

    it outputs it,

    the program only stored the image name and extension in one mysql block,then the image itself is not stored, :(
     
    tldmic, Feb 21, 2010 IP
  4. ryantetek

    ryantetek Peon

    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if (file_exists("C:/upload" . $_FILES["file"]["name"]))
    Code (markup):

    i think it has a missing slash for the directory?

    if (file_exists("C:/upload/" . $_FILES["file"]["name"]))
    Code (markup):
     
    ryantetek, Feb 21, 2010 IP
  5. tldmic

    tldmic Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    hi,

    thank you all, i got it right,the error was that there was no link between the html name and the php,so each itme, it was giving error due to the missing name :)

    thanks
    :)
     
    tldmic, Feb 21, 2010 IP