SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Hybrid View

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

    Question how do i convert this to send photo to my server

    ok i have this form which sends all details to database and emails me with attachment if they have a photo
    instead of that i wanted the photo to go to my server in a folder where all photos stored

    this is my form

    PHP Code:
    <form action="add1.php" method="post" enctype="multipart/form-data">
       <
    table width="604" border="0" cellspacing="5">
        <
    tr>
          <
    td><span class="style2">Name: <span class="style3">not shown</span></span></td>
          <
    td>
            <
    div class="style2">
              <
    input name="name" type="text" id="name" size="30" />
            </
    div></td>
        </
    tr>
        <
    tr>
          <
    td><span class="style2">Email:</spannot shown</td>
          <
    td><input name="email" type="text" id="email" size="30" /></td>
        </
    tr>
        <
    tr>
          <
    td><span class="style2">Tel:</span></td>
          <
    td><input name="tel" type="text" id="tel" size="15" /></td>
        </
    tr>
        <
    tr>
          <
    td><span class="style2">Lost/Found:</span></td>
          <
    td><select name="state">
              <
    option value="lost">LOST</option>
              <
    option value="found">FOUND</option>
            </
    select>
              <
    br /></td>
        </
    tr>
        <
    tr>
          <
    td><span class="style2">Dog/Cat:</span></td>
          <
    td><select name="type">
              <
    option value="dog">Dog</option>
              <
    option value="cat">Cat</option>
            </
    select>
              <
    br /></td>
        </
    tr>
        <
    tr>
          <
    td><span class="style2">AreaFound or Lost</span></td>
          <
    td><input name="area" type="text" id="area" size="30" /></td>
        </
    tr>
        <
    tr>
          <
    td valign="top"><span class="style2">Description:</span></td>
          <
    td><textarea name="desc" cols="30" rows="6" id="desc"></textarea></td>
        </
    tr>
        <
    tr>
          <
    td>PhotoRename your photo to see below</td>
          <
    td><input type="file" name="pic" /></td>
        </
    tr>
        <
    tr>
          <
    td>Anti-Spam QuestionHow many legs on a Dog ?</td>
          <
    td><input name="leg" type="text" id="leg" size="3" /></td>
        </
    tr>
        <
    tr>
          <
    td>Picture Number as below if no pic then enter 1 for dog 2 for cat</td>
          <
    td><input name="pnum" type="text" id="pnum" size="3" /></td>
        </
    tr>

        <
    tr>
          <
    td><input name="send" type="submit" id="send" onclick="MM_validateForm('name','','R','email','','NisEmail','tel','','RisNum','area','','R','desc','','R');return document.MM_returnValue" value="Send" /></td>
        </
    tr>
      </
    table>
    </
    form>

                    
                    </
    div
    and here is the action form

    PHP Code:
    //This gets all the other information from the form
    $state=$_POST['state']; 
    $type=$_POST['type'];
    $area=$_POST['area'];
    $desc=$_POST['desc'];
    $name=$_POST['name'];
    $email=$_POST['email'];
    $tel=$_POST['tel'];
    $pnum=$_POST['pnum'];
    $date date("d-m-Y");
    $pname=$pnum.".jpg";

    // Connects to your Database 
     
    $dbh=mysql_connect("localhost""vcd""57") or die('I cannot connect to database because: ' .mysql_error()) ; 
    mysql_select_db("pets"); 

    //Writes the information to the database 
    mysql_query("INSERT INTO `register` VALUES ('$id', '$state', '$type', '$area', '$desc', '$name', '$email', '$tel', '$pname', '$date')");

    //compose the mail message        
     
    $msg"New Record\n Region: $region, Name: $name, Email: $email ";       
    //send the mail       
    mail('d@gmail.com','New Record',$msg)

    ?> 
    many thanks
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use move_uploaded_file() to save the file to a specific directory.

  3. #3
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes i read that some where but cant remeber how to do that
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The official php manual is always a great place to learn more about a function. You just goto
    php.net/FUNCTION_NAME_HERE

    for example
    www.php.net/move_uploaded_file

    There's usually a lot of user posted comments as well for most functions. This may help too
    http://www.php.net/manual/en/feature...ost-method.php

  5. #5
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks again for info had a look dont begin to understand it
    but all the examples seem to have just upload on a form by itself
    where i have a few fields
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  6. #6
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dougvcd View Post
    but all the examples seem to have just upload on a form by itself
    where i have a few fields
    This wouldn't matter.
    PHP Code:
    $state=$_POST['state']; 
    $type=$_POST['type'];
    $area=$_POST['area'];
    $desc=$_POST['desc'];
    $name=$_POST['name'];
    $email=$_POST['email'];
    $tel=$_POST['tel'];
    $pnum=$_POST['pnum'];
    $date date("d-m-Y");
    $pname=$pnum.".jpg";

    move_uploaded_file($_FILES['pic']['tmp_name'], 'path/to/your/uploads/'.$pname);

    # rest of your code 

  7. #7
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please filter your variables. :P

  8. #8
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  9. #9
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    move_uploaded_file($_FILES['pic']['tmp_name'], 'upload/'.$pname); 
    this didnt work have i missed some thing out
    Doug
    ok photo now goes to server but no name just .jpg when it should be eg 7.jpg
    Last edited by dougvcd; Apr 27, 2009 at 05:11. Reason: more info
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  10. #10
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks to all now sorted
    cheers
    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
  •