SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast Misery's Avatar
    Join Date
    Aug 2003
    Location
    England
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Making a news script that uploads image aswell then displays it with post??

    How would I make a news script that I can also select an image to upload and then on the news.php it shows the news then the image that got uploaded?
    <---Noob


  2. #2
    SitePoint Zealot
    Join Date
    Sep 2002
    Location
    Calgary
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are a lot of articals on google but some things that help me.

    1) Is your image going to be stored within a database or on the server. I would recommend on the server simplicity reasons.

    2) Your form needs to have enctype="multipart/form-data

    here is something that should give you a starting point.

    PHP Code:

    <?
       
    if (isset($_POST['news_artical'])){
            if (
    $_FILES['imagefile']['type'] == "image/gif"){
                
    copy ($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name'])
                    or die (
    "Could not copy");
                echo 
    "";
                echo 
    "Name: ".$_FILES['imagefile']['name']."";
                echo 
    "Size: ".$_FILES['imagefile']['size']."";
                echo 
    "Type: ".$_FILES['imagefile']['type']."";
                echo 
    "Copy Done....";
            }
            else {
                echo 
    "";
                echo 
    "Could Not Copy, Wrong Filetype (" $_FILES['imagefile']['name'] . ")";
            }
       }
    ?>


    <form action="updateNews.php" method="post" enctype="multipart/form-data">
    <input type="file" name="news_image" accept="image/gif">
    <input type="submit" name="news_artical">
    </form>
    I have not tested this, but give it a try.


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
  •