Code To Upload Image

Welcome. Please Login, Register, Or Activate! 
type your username and password to login
Date: March 14, 2010, 05:27 PM
491664 members and 354181 Topics
Latest Member: tunji24
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Programming  |  Code To Upload Image
Pages: (1) Go Down Send this topic Notify of replies
Author Topic: Code To Upload Image  (Read 219 views)
kelechiodo (m)
Code To Upload Image
« on: July 09, 2009, 03:36 PM »

I am using php to design a website. Now, I'm looking for help on either php or java code that will help me to upload image. The image is to appear on a form, just like WAEC and JAMB own. Please can anyone help.
lojik (m)
Re: Code To Upload Image
« #1 on: July 09, 2009, 10:24 PM »

<!-- html form to upload your image -->
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
<input type="file" name="uploaded_image" id="uploaded_image" />
</form>



//example PHP code to receive and save picture from d above form:
$fileName = $_FILES['uploaded_image']['name'];
$tmpName = $_FILES['uploaded_image']['tmp_name'];
$pixDir = "./the_folder_you_will_be_saving_pictures_to/";

// get the file extension first
$ext = substr(strrchr($fileName, "."), 1);

// and now we have to specify the path and filename to save as
$filePath = $pixDir . $_POST["member_id"] . '.' . $ext;  //member id is your unique identifier for each member

 //move the file to the new folder //move the file to the new folder
$result = move_uploaded_file($tmpName, $filePath);
if(!$result) die("could not save picture");

//set the path to the file in you database so you can use it to fetch the pix later
$query = "UPDATE memberTable SET image_path = '".$filePath ."' WHERE member_id = ".$_POST["member_id"];
$result = mysql_query($query);
if(!$result) die("could not save picture");


The codes above were modified for you from Alumnia opensource portal available at http://www.afrisoft.org for free. it was taken from the edit.php file in the alumnia root directory. you can download Alumnia free to see the entire picture upload/display code.
Big Star (m)
Re: Code To Upload Image
« #2 on: July 10, 2009, 04:15 PM »

thanks bross
kelechiodo (m)
Re: Code To Upload Image
« #3 on: July 18, 2009, 04:54 PM »

Dear Lojik, thanks alot. You really helped.
 How To Sorting Tables With Vb.6  Need Help With Visual Studio .net 2003 Class Programming  Novice In It: Come Enlighten Me  Page 2
Pages: (1) Go Up Send Topic to Friend by E-mail Reply 


Sections: Autos/Cars (2) Jobs/Vacancies (2) (3) Career Talk Education General(2) Politics Romance Computers Phones Travel
Sports Fashion Health Religion Celebrities TV/Movies (2) Music/Radio (2) Books Webmasters Programming

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa. See also: Privacy Policy Nairalist.
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.