php mysql Upload image to folder and store filename in mysql

Discussion in 'PHP' started by xbat, Dec 3, 2012.

  1. #1
    Hello,

    this is what I have.... I was trying to do a input with a hidden tag but it doesn't seem to be working.. Anyone have any ideas or suggestions?

    thanks

    :cool:

    <?php
    $allowedExts = array("jpg", "jpeg", "gif", "png");
    $extension = end(explode(".", $_FILES["photo"]["name"]));
    if ((($_FILES["photo"]["type"] == "image/gif")
    || ($_FILES["photo"]["type"] == "image/jpeg")
    || ($_FILES["photo"]["type"] == "image/png")
    || ($_FILES["photo"]["type"] == "image/pjpeg"))
    && ($_FILES["photo"]["size"] < 2000000)
    && in_array($extension, $allowedExts))
      {
      if ($_FILES["photo"]["error"] > 0)
        {
        echo "Return Code: " . $_FILES["photo"]["error"] . "<br>";
        }
      else
        {
        echo "Upload: " . $_FILES["photo"]["name"] . "<br>";
        echo "Type: " . $_FILES["photo"]["type"] . "<br>";
        echo "Size: " . ($_FILES["photo"]["size"] / 2024) . " kB<br>";
        echo "Temp file: " . $_FILES["photo"]["tmp_name"] . "<br>";
    
        if (file_exists("myphotos/" . $_FILES["photo"]["name"]))
          {
          echo $_FILES["photo"]["name"] . " already exists. ";
          }
        else
          {
          move_uploaded_file($_FILES["photo"]["tmp_name"],
          "mystock/" . $_FILES["photo"]["name"]);
          echo "Stored in: " . "myphotos/" . $_FILES["photo"]["name"];
          }
        }
      }
    else
      {
      echo "Invalid file";
      }
    ?> 
    
    
    
    
    <form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST" enctype="multipart/form-data">
      <label for="image"></label>
    - 
     <input type="file" name="image1" id="image1" /> 
    <input  type="hidden" name="image1" id="image1"  />
     <BR /><BR /> 
    
       <input type="submit" name="submit" id="submit" value="Submit" />
       <input type="hidden" name="MM_insert" value="form1" />
    </form>
    PHP:
     
    xbat, Dec 3, 2012 IP
  2. xbat

    xbat Well-Known Member

    Messages:
    326
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    105
    #2
    I figured it out... it had to do with my GetSQLValueString instead of using $file I was using $post.... :)
     
    xbat, Dec 3, 2012 IP
  3. Maulik12

    Maulik12 Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; }

    This code is very useful for you. you are upload any type of files and images.
     
    Maulik12, Dec 4, 2012 IP