dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] uploading images

Hybrid View

  1. #1
    Join Date
    Oct 2011
    Location
    Hamilton, Ontario
    Posts
    84

    resolved [RESOLVED] uploading images

    having trouble figuring out why this won't work. the picture doesn't appear in the directory afterwards and instead of a file path string in the db, it just says null in the next row in the db

    PHP Code:
    <?php
    //connect to database
      
    include('scripts/db.php');

    //get text and page name
      
    $page=$_GET['page'];
      
    $content=$_POST['add_entry_text'];
      
    $category=$_GET['page'];

    //insert primary info into database
      
    $db->query("INSERT INTO ENTRIES(DATE, TEXT, category) VALUES (CURDATE(),'".$content."','".$page."')");

      if(isset(
    $_FILES["entry_pic"])){
        
    $allowedExts = array("gif""jpeg""jpg""png");
          
    $location explode("."$_FILES["entry_pic"]["name"]);
          
    $extension end($location);
        if (((
    $_FILES["entry_pic"]["type"] == "image/gif")
          || (
    $_FILES["entry_pic"]["type"] == "image/jpeg")
          || (
    $_FILES["entry_pic"]["type"] == "image/jpg")
          || (
    $_FILES["entry_pic"]["type"] == "image/png"))
          && (
    $_FILES["entry_pic"]["size"] < 120000)
          && 
    in_array($extension$allowedExts))
        {
            if (
    $_FILES["entry_pic"]["error"] > 0)
              {
              echo 
    "Return Code: " $_FILES["entry_pic"]["error"] . "<br>";
              }
            else{
              
    $target="entry_pics/".$_FILES['entry_pic']['name'];
              
    move_uploaded_file($_FILES['entry_pic']['tmp_name'], $target); 
              
    $db->query("UPDATE entries SET entry_pic_path = 'entry_pics/".$_FILES['entry_pic']['name']."'
                WHERE text='"
    .$content."'");
            }
        }else{
          echo 
    "Invalid file";
        }
      }      
      
    header("Location:index.php");
    ?>

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,589
    Your HTML? often these issues are based in what you put in your form tag.

    You will also find a thread that is stickied with a script for uploading images.

    My initial thoughts on your problem is to check that your enctype tag in your form is set.
    If your post falls off the page, bump it. ...
    Please remember to wrap any code you have in forum tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  3. #3
    Join Date
    Oct 2011
    Location
    Hamilton, Ontario
    Posts
    84
    Oh my heck... lol i feel stupid now... yea it was my lack of enctype='multipart/form-data'. thanks a ton for that... silly dumb mistakes... I've done this before so I don't know why i forgot that. thanks for the reminder.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles