Uploading Image using PHP and mySQL

From: Date: Mon, 18 Feb 2008 23:43:04 +0000
Subject: Uploading Image using PHP and mySQL
Groups: php.db 
Request: Send a blank email to php-db+get-44622@lists.php.net to get a copy of this message
Hi All, First of all A very big thank you to all of you for solving my Password() encryption problem. Now I'm stuck on new problem which is image not uploading. I'm using the following code. Regards Nasreen <?php include ("header.php"); include ("dbconnect.php"); $submit=$_REQUEST["submit"] ; $aname=$_REQUEST["aname"]; $aboutu=$_REQUEST["urself"]; $file=$_REQUEST["file"]; $url_provided = $_REQUEST["url_provided"]; echo($aname); if ($submit == "Sign!") { function getImageFile($file){ $takeFile = fopen($file, "r"); $file = fread($takeFile, filesize($file)); fclose($takeFile); return $file; } function getfileType( $name ){ $name = explode(".", $name); $name = array_reverse($name); $name = $name[0]; return $name; } $allowedImageTypes = array("gif","jpg","png"); if(empty($_FILES['image_file']['tmp_name'])){ echo "File not uploaded"; } else { $fileType = $_FILES['file']['name']; if(in_array(getfileType($fileType), $allowedImageTypes)){ $fileContent = getImageFile($_FILES['file']['tmp_name']); $uploadedImage = chunk_split(base64_encode($fileContent)); $query = "INSERT INTO artist (name,about_u,imgdata, profile_url) VALUES('$aname','$aboutu','$uploadedImage','$url_provided')"; $result = mysql_query($query); if(mysql_affected_rows() > 0){ echo "Image has been inserted succesfully"; } else { echo "Image can not be inserted check your submission"; } } else { echo "This is not a true image type"; } } } ?> <div align="center" class="style1"> <h1>Artist Profile Form</h1> <p>&nbsp;</p> <form action="artist.php" method="post" enctype="multipart/form-data"> <table width="397" border="0"> <tr> <th width="221" scope="col"><h4 align="right">Name:</h4></th> <th width="166" scope="col"><div align="left"> <input name="aname" type="text" id="username3"> </div></th> </tr> <tr> <th scope="row"><div align="right">About Yourself </div></th> <td><div align="left"> <textarea name="urself"></textarea> </div></td> </tr> <tr> <th scope="row"><div align="right"> Profile export from myspace/face book </div></th> <td><div align="left"> <input name="url_provided" type="text" id="repass"> </div></td> </tr> <tr> <th scope="row"><div align="right">Upload Photo </div></th> <td><div align="left"> <input type="file" name="file"> </div></td> </tr> <tr> <th scope="row">&nbsp;</th> <td> <input type="submit" name="submit" value="Sign!"> <input type="reset" name="Reset" value="Reset"></td> </tr> </table> </form> <p><strong></strong></p> </div> ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

« previous php.db (#44622) next »