0

HI there.. I've spend almost a day looking for a script for image upload but unfortunately, i see none. so, I consider writing a thread here at daniweb so the advance programmer there will help me with my problem.

Please help me in creating a script that will enable the user to upload their 1X1 size photos.. please help me since i don't have any idea on how can to do it.

Please guys.. i know there is a lot out there who knew this..

Thanks in advance.

God Bless You All

2
Contributors
4
Replies
12
Views
6 Years
Discussion Span
Last Post by nyler01
0

Set up a database, set datatype as blob. Here is the minimum code that you should use.You can perform additional validation and stuff for better safety and performance reasons.

if(isset($_POST['upload']))
{
if (isset($_FILES['photo']))
        {
            @list(, , $imtype, ) = getimagesize($_FILES['photo']['tmp_name']);
            

            if ($imtype == 3) 
                $ext="png";   
            elseif ($imtype == 2)
                $ext="jpeg";
            elseif ($imtype == 1)
                $ext="gif";
            else
                $msg = 'Error: unknown file format';

            if (!isset($msg)) 
            {
                $data = file_get_contents($_FILES['photo']['tmp_name']);
                $data = mysql_real_escape_string($data);
                

                mysql_query("INSERT INTO {$table}
                                SET ext='$ext', title='$title',
                                    data='$data'"); //define your db.php and table name etc, its your job :)

                $msg = 'Success: image uploaded';
            }
        }
}
<form action="<?=$PHP_SELF?>" method="POST" enctype="multipart/form-data">
<label for="title">Title:</label><br>
<input type="text" name="title" id="title" size="64"><br><br>

<label for="photo">Photo:</label><br>
<input type="file" name="photo" id="photo"><br><br>

<input type="submit" name="upload" value="upload">
</form>

By the way you can do it without database also. But I'm not good at that :)

Edited by TechySafi: n/a

0

I'm sorry but i used your script and nothing happens. why is that? i tried to figure it out but i'm can't find a way..

0

what do you mean by nothing happens? plz explain the error!

0

There is no error coming out.. it just keep on coming back from the start after i click the submit button. by the way.. i somehow manage to update a photo in afolder and i stored the location details in the database.. what i need now is how can i see the uploaded image dynamically after uploading the image..

What i mean is this.

on the main page.. there is an upload button which leads to a pop up window .. after uploading the photo.. the pop up window will close and the parent window will automatically refresh to get the image recently uploaded into the database..

Thanks a lot in advance.
God Bless You

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.