Post
by ra1 » Mon Sep 03, 2012 8:29 am
hello ,, Aidan38
i have a bit of problem ..with image uploading in my project .... will u plz help me ...
this is my code for file uploading ...
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
//if it is not empty
if ($image)
{
//get the original name of the file from the clients machine
$filename = stripslashes($_FILES['image']['name']);
//get the extension of the file in a lower case format
$extension = $this->getExtension($filename);
echo $extension;
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file,
//otherwise we will do more tests
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
echo "2";
//print error message
echo '<h1>Unknown extension!</h1>';
$errors=1;
}
else
{
//get the size of the image in bytes
//$oname=$_FILES['image']['tmp_name'] is the temporary filename of the file
//in which the uploaded file was stored on the server
$size=filesize($_FILES['image']['tmp_name']);
//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1024)
{
echo '<h1>You have exceeded the size limit!</h1>';
$errors=1;
}
//we will give an unique name, for example the time in unix time format
$image_name=$image;
$ran=rand(10000,9999);
//the new name will be containing the full path where will be stored (images folder)
$saveimage="images/stories/******/pictures/".$ran.$image_name;
$db=JFactory::getDBO();
$sql="SELECT *
FROM ".$db->nameQuote('table name')."
WHERE ".$db->nameQuote('image field of database')." = ".$db->quote($saveimage)."; ";
$db->setQuery($sql);
$count=$db->loadResult(); //$logos = $database->loadObjectList();
$row = $db->loadAssoc();
print_r($row);
if($resultx=$db->query()){
// unset($db);
}else{
$db->stderr();
}
$countval=$db->getNumRows( $resultx );
$data =new stdClass();
$data->id from database = JFactory::getUser()->id;
$data->image path from database= $saveimage;
if($countval==0){
echo $countval;
if($db->insertObject("table name", $data, 'id from database')){
unset($db);
}else{
$db->stderr();
}
}
else
{
if($db->updateObject("table name", $data, 'id from database')){
unset($db);
}else{
echo $db->stderr();
}
}
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $saveimage);
if (!$copied)
{
echo '<h1>Copy unsuccessfull!</h1>';
$errors=1;
}}
//If no errors registred, print the success message
if(!$errors)
{
echo "<h1>File Uploaded Successfully! Try again!</h1>";
}
i have to upload file in database and show it in the display like profile pic in social networking site.... the image path can be stored successfully but i cant see the image on display ... plz help me...