Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.