For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > February 2008 > Uploading Image using PHP and mySQL









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Uploading Image using PHP and mySQL
Nasreen Laghari

2008-02-18, 10:02 pm

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','$uploadedImag
e','$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> </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"> </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.


________________________________________
________________________________________
____
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com