Jump to content

HOW TO UPLOAD IMAGES IN php


lekhya

Recommended Posts

Hi frnz,

i'm new to php. can anyone help me how to upload images in php.

i tried this code but doesn't work.

 

<HTML>
        <HEAD>
                <title>WebForm44</title>

        </HEAD>
        <body >
                <form id="Form1" method="post" runat="server">
                        <INPUT style="Z-INDEX: 101; LEFT: 320px; POSITION: absolute; TOP: 240px" type="file"><INPUT style="Z-INDEX: 102; LEFT: 320px; WIDTH: 155px; POSITION: absolute; TOP: 72px; HEIGHT: 152px"
                                type="text">
                </form>


                <?php



                  $con = odbc_connect("student1","root","admin");
if (!$con)
  {
  die('Could not connect: ' . odbc_error());
  }
  $pid=$_POST['pid'];
$title=$_POST['title'];
$imgdata=$_POST['imgdata'];



  if ($_REQUEST[completed] == 1) {
        // Need to add - check for large upload. Otherwise the code
        // will just duplicate old file ;-)
        // ALSO - note that latest.img must be public write and in a
        // live appliaction should be in another (safe!) directory.
        move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img");
        $instr = fopen("latest.img","rb");
        $image = addslashes(fread($instr,filesize("latest.img")));
        if (strlen($instr) < 149000) {
                mysql_query ("insert into pix (title, imgdata) values (\"".
                $_REQUEST[whatsit].
                "\", \"".
                $image.
                "\")");
        } else {
                $errmsg = "Too large!";
        }
}
     // Find out about latest image

$gotten = @mysql_query("select * from pix order by pid desc limit 1");
if ($row = @mysql_fetch_assoc($gotten)) {
        $title = htmlspecialchars($row[title]);
        $bytes = $row[imgdata];
} else {
        $errmsg = "There is no image in the database yet";
        $title = "no database image available";
        // Put up a picture of our training centre
        $instr = fopen("../wellimg/ctco.jpg","rb");
        $bytes = fread($instr,filesize("../wellimg/ctco.jpg"));
}

// If this is the image request, send out the image

if ($_REQUEST[gim] == 1) {
        header("Content-type: image/jpeg");
        print $bytes;
        exit ();
        }

                ?>
        </body>
</HTML>

 

 

edit by redbullmarky - please aquaint yourself with the Caps Lock key - writing in capitals is considered shouting. also, please check where you post as @phpfreaks is for stuff relating to this site.

Link to comment
https://forums.phpfreaks.com/topic/50608-how-to-upload-images-in-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.