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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    help with uploading image to folder from database id

    Hie people i'm trying to create an update link that will upload an image onto to the server from the with the id number as a refrence when that information is viewed again, but all the time when i upload the image it does nothing, used the echo to view what id number was output and at the moment the $_post has the database id where the image is linked to

    PHP Code:
    <?
    // Connect to database
    include_once "../../scripts/connect_to_members_mysql.php";

    //check for required from variables
    if (!$_POST[id]){
        
    header("Location: /pick_modrecord.php");
        exit;
        }


    // Parsing section for the member picture... only runs if they attempt to upload or replace a picture
    if ($_POST['parse_var'] == "pic"){

            if (!
    $_FILES['fileField']['tmp_name']) { 
            
                
    $error_msg '<font color="#FF0000">ERROR: Please browse for an image before you press submit.</font>';
                
            } else {

                
    $maxfilesize 51200// 51200 bytes equals 50kb
                
    if($_FILES['fileField']['size'] > $maxfilesize ) { 

                            
    $error_msg '<font color="#FF0000">ERROR: Your image was too large, please try again.</font>';
                            
    unlink($_FILES['fileField']['tmp_name']); 

                } else if (!
    preg_match("/\.(gif|jpg|png)$/i"$_FILES['fileField']['name'] ) ) {

                            
    $error_msg '<font color="#FF0000">ERROR: Your image was not one of the accepted formats, please try again.</font>';
                            
    unlink($_FILES['fileField']['tmp_name']); 

                } else { 

                            
    $newname "image01.jpg";
                            
    $place_file move_uploaded_file$_FILES['fileField']['tmp_name'], "members/$_POST[id]/".$newname);
                            
    $success_msg '<font color="#009900">Your image has been updated, it may take a few minutes for the changes to show... please                                                    be patient.</font>';
                }

            } 
    // close else that checks file exists

    }/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //
    //build and issue query
    $sql "SELECT id, firstname, lastname, burial_site, date_of_burial, bio_body FROM $table_name WHERE id = '$_POST[id]'";
    $result = @mysql_query($sql) or die(mysql_error());

    //get results for display
    While    ($row mysql_fetch_array($result)){
            
    $firstname $row['firstname'];
            
    $lastname$row['lastname'];
            
    $burial_site $row['burial_site'];
            
    $date_of_burial $row['date_of_burial'];
            
    $bio_body $row['bio_body'];
            
    ///////  Mechanism to Display Pic. See if they have uploaded a pic or not  //////////////////////////
            
    $check_pic "../../members/$_POST[id]/image01.jpg";
            
    $default_pic "../../members/0/image01.jpg";
            if (
    file_exists($check_pic)) {
               
    $user_pic "<img src=\"$check_pic\" width=\"100px\" />"// forces picture to be 100px wide and no more
            
    } else {
            
    $user_pic "<img src=\"$default_pic\" width=\"100px\" />"// forces default picture to be 100px wide and no more
            
    }
            }
            echo 
    "$id";
            echo 
    "$_POST[id]";
            echo 
    "$_POST[id]";
    ?>
    this is the front end as well

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Record Management System(RMS) - Modify Record</title>
    <link href="style/main.css" rel="stylesheet" type="text/css" />
    <link rel="icon" href="http://www.yourdomain.com/favicon.ico" type="image/x-icon" />
    <link rel="shortcut icon" href="http://www.yourdomain.com/favicon.ico" type="image/x-icon" />
    <link href="../../style/main.css" rel="stylesheet" type="text/css" />
    </head>

    <BODY>
    <h1>Record management system</h1>
    <h2><em> Modify a Record</em></h2>

    <FORM METHOD="POST" ACTION ="do_modrecord.php">
    <INPUT TYPE="hidden" name="id" value="<? echo "$_POST[id]"?>">


    <table cellspacing=3 cellpadding=5>
    <tr> <th width="210">
      Name &amp; Site Burial Information</th>
    <th colspan="2">OTHER INFORMATION</th>
    </tr>
    <tr>
      <td valign=top><?php print "$user_pic"?></td>
      <td width="436" valign=top><input name="fileField" type="file" class="formFields" id="fileField" size="42" />
              50 kb max</TD>
    </tr>
    <tr>
    <td valign=top>
    <p><STRONG> First Name: </STRONG><BR>
    <INPUT TYPE="text" NAME = "firstname" VALUE ="<? echo "$firstname"?>" SIZE=35 MAXLENGTH=100></p>
    <p><STRONG> Last Name: </STRONG><BR>
    <INPUT TYPE="text" NAME = "lastname" VALUE ="<? echo "$lastname"?>" SIZE=35 MAXLENGTH=100></p>
    <p><STRONG> Burial Site</STRONG><BR>
    <INPUT TYPE="text" NAME = "burial_site" VALUE ="<? echo "$burial_site"?>" SIZE=35 MAXLENGTH=100></p></td>
    <td colspan="2" valign=top>
    <p><STRONG> Date of Burial (YYYY/MM/DD)</STRONG><BR>
    <INPUT TYPE="text" NAME = "date_of_burial" VALUE ="<? echo "$date_of_burial"?>" SIZE=35 MAXLENGTH=100></p>
    <p><STRONG> Bio Body</STRONG><BR>
      <textarea name="bio_body" cols="100" rows="10"><? echo "$bio_body"?></textarea>
    </p></TD>
    </tr>

    <tr>
    <td align=center colspan=3><br>
    <input name="parse_var" type="hidden" value="pic" />
    <INPUT TYPE="SUBMIT" NAME="submit" VALUE="Update Record">
    <br>
    <p><a href="../members.php">Return to Admin page</a></p></TD>
    </TR>
    </TABLE>

    </FORM>
    </BODY>
    </HTML>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Just looking at the html, you cannot upload with a standard form.
    You'll need to add enctype="multipart/form-data" to you're form tag in order to deal with uploads, and of course it has to be post method (which you do have).

    I'm a little busy atm so I can't look over the rest of this, but post back if you still have problems and I'll see if I can help tonight before I go home (I don't have the net at home right now)
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    sorry don't mean to be blunt, but where abouts u want me to put that code , thanks

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Sorry, replace the form tag in the html itself:
    Code:
    <!-- replace this: -->
    <FORM METHOD="POST" ACTION ="do_modrecord.php"> 
    
    <!-- with this -->
    <FORM METHOD="POST" ACTION ="do_modrecord.php" enctype="multipart/form-data">
    And sorry I won't be able to help past this, so I hope this is the only trouble O.o
    this is a common pitfall with file uploads in php.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    Allens (02-23-2010)

  • #5
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks for that, getting some were now, its now saying can't find the folder its moving it to, hopefully i can sort it out... if not be back

  • #6
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    just found the problem in my do_modrecord.php because it working in different folders had to add ../../, thanks for the help

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Great, glad you got it working mate
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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