954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to Upload Image,file

Hi this is Scorpionz
Can any have an idea...
How to Upload image,file in PHP
and store it in Database....
and How to call it to view on Front End means to my Html Page Web page....
and How to Specify Space that Uploading File size

Any Help will be Highly Appreciated....

Thanks and Regards
ScorpionZ

scorpionz
Junior Poster
109 posts since Sep 2006
Reputation Points: 13
Solved Threads: 0
 
carobee
Posting Whiz in Training
209 posts since Dec 2007
Reputation Points: 10
Solved Threads: 12
 

first of all Thanks Mr carobee for referring such articles ... now let me define things of my side

I have done it With uploading , first of all let me give u my Piece of code.

function upload_img($img)
{

if((!empty($_FILES["product_upload_img"])) && ($_FILES['product_upload_img']['error'] == 0)) {
//Check if the file is JPEG image and it's size is less than 350Kb
$filename = basename($_FILES['product_upload_img']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext == "jpg") && ($_FILES["product_upload_img"]["type"] == "image/jpeg") &&
($_FILES["product_upload_img"]["size"] < 350000)) {
//Determine the path to which we want to save this file
//$newname = './dataAuthor/'.$filename;
// $newname = 'C:\xampp\htdocs\online_shopping\uploaded_images\ $filename';
$newname = 'C:\xampp\htdocs\online_shopping\uploaded_images\$filename';
//Check if the file with the same name is already exists on the server
if (!file_exists($newname)) {
//Attempt to move the uploaded file to it's new place
if ((move_uploaded_file($_FILES['product_upload_img']['tmp_name'],$newname))) {
echo "It's done! The file has been saved as: ".$newname;
} else {
echo "Error: A problem occurred during file upload!";
}
} else {
echo "Error: File ".$_FILES["product_upload_img"]["name"]." already exists";
}
} else {
echo "Error: Only .jpg images under 350Kb are accepted for upload";
}
} else {
echo "Error: No file uploaded";
}
}

This is a code of separate file of uploading... i have made it as a function... but i want this to be done without function

Now let me give u the HTML

scorpionz
Junior Poster
109 posts since Sep 2006
Reputation Points: 13
Solved Threads: 0
 
first of all Thanks Mr carobee

its not Mr but Ms for referring such articles ... now let me define things of my side

I have done it With uploading , first of all let me give u my Piece of code.

function upload_img($img)
{

if((!empty($_FILES["product_upload_img"])) && ($_FILES['product_upload_img']['error'] == 0)) {
//Check if the file is JPEG image and it's size is less than 350Kb
$filename = basename($_FILES['product_upload_img']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext == "jpg") && ($_FILES["product_upload_img"]["type"] == "image/jpeg") &&
($_FILES["product_upload_img"]["size"] < 350000)) {
//Determine the path to which we want to save this file
//$newname = './dataAuthor/'.$filename;
// $newname = 'C:\xampp\htdocs\online_shopping\uploaded_images\ $filename';
$newname = 'C:\xampp\htdocs\online_shopping\uploaded_images\$filename';
try this
$newname="C:\xampp\htdocs\online_shopping\uploaded_images\";
$newname=$newname.basename($_FILES['product_upload_img']['name']);
//Check if the file with the same name is already exists on the server
if (!file_exists($newname)) {
//Attempt to move the uploaded file to it's new place
if ((move_uploaded_file($_FILES['product_upload_img']['tmp_name'],$newname))) {
echo "It's done! The file has been saved as: ".$newname;
} else {
echo "Error: A problem occurred during file upload!";
}
} else
also print the error number here $_FILES['product_upload_img']['error'] {
echo "Error: File ".$_FILES["product_upload_img"]["name"]." already exists";
}
} else {
echo "Error: Only .jpg images under 350Kb are accepted for upload";
}
} else {
echo "Error: No file uploaded";
}
}

This is a code of separate file of uploading... i have made it as a function... but i want this to be done without function

Now let me give u the HTML
xmlns="http://www.w3.org/1999/xhtml">

Add Product Information
<?php

if(isset($_POST['add_product']))
{
$prod_img = $_FILES["product_upload_img"]["name"];

upload_img($_FILES["product_upload_img"]["name"]);
$sql_insert_product = "insert into product_information (product_upload_img) values ('$prod_img')";
$result_insert_product = mysql_query($sql_insert_product);
echo $sql_insert_product;

}
?>

Upload Image



carobee
Posting Whiz in Training
209 posts since Dec 2007
Reputation Points: 10
Solved Threads: 12
 

i don't recommend using the orginal file name. you will run into the same problem over and over again if you upload the same file at all. use the time() function to give each uploaded image a unique name.

kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You