SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question having probs with this upload code

    ok this upload code is send info to database but will not upload pic to server can any one see what i have done wrong
    cheers
    Doug
    PHP Code:
    <?php 

    //This is the directory where images will be saved 
    $target "images2/"
    $target $target basename$_FILES['photo']['name']); 

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

    // Connects to your Database 
    mysql_connect("localhost""vcd""57") or die(mysql_error()) ; 
    mysql_select_db("caravanh_pets") or die(mysql_error()) ; 

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

    //Writes the photo to the server 
    if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 


    //Tells you if its all ok 
    echo "The file "basename$_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"

    else { 

    //Gives and error if its not 
    echo "Sorry, there was a problem uploading your file."

    ?>
    HTML Code:
    <form enctype="multipart/form-data" action="add2.php" method="POST"> 
    Name: <input type="text" name="name"><br> 
    E-mail: <input type="text" name = "email"><br> 
    Pets Name: <input type="text" name = "pet"><br> 
    Photo: <input type="file" name="photo"><br> 
    <input type="submit" value="Add"> 
    </form>
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  2. #2
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    change
    PHP Code:
    echo "The file " basename($_FILES['uploadedfile']['name']) .
                
    " has been uploaded, and your information has been added to the directory"
    to
    PHP Code:
    echo "The file " basename($_FILES['photo']['name']) .
                
    " has been uploaded, and your information has been added to the directory"
    my mobile portal
    ghiris.ro

  3. #3
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try debugging
    PHP Code:
    <pre>
    <?php
    ini_set
    ("display_errors"1);
    error_reporting(E_ALL);

    print_r($_FILES);

    if (isset(
    $_POST['submit']))
    {
        
    //This is the directory where images will be saved
        
    $target "images2/";
        
    $target $target basename($_FILES['photo']['name']);

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

        
    // Connects to your Database
        
    mysql_connect("localhost""vcd""57") or die(mysql_error());
        
    mysql_select_db("caravanh_pets") or die(mysql_error());

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

        
    //Writes the photo to the server
        
    if (move_uploaded_file($_FILES['photo']['tmp_name'], $target))
        {
            
    //Tells you if its all ok
            
    echo "The file " basename($_FILES['photo']['name']) .
                
    " has been uploaded, and your information has been added to the directory";
        }
        else
        {
            
    //Gives and error if its not
            
    echo "Sorry, there was a problem uploading your file.";
        }
    }
    ?>

    <form enctype="multipart/form-data" action="test.php" method="POST"> 
    Name: <input type="text" name="name" /><br> 
    E-mail: <input type="text" name = "email" /><br> 
    Pets Name: <input type="text" name = "pet" /><br> 
    Photo: <input type="file" name="photo" /><br> 
    <input type="submit" name="submit" value="Add"> 
    </form>
    my mobile portal
    ghiris.ro

  4. #4
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    first you must sure the target folder writable (chmod)
    then make the $target = real_path
    eYeew! Founder and Developer

    Madipta

  5. #5
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers Ernie
    that worked first time
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net


Bookmarks

Posting Permissions

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