Start New Discussion within our Web Development Community

Is there anyone who can explain to me how can i store image in a folder to the server then the path to mysql.
i dont know even how to get started,i will appreciate for your help.
Or links where i can find the tutorials.

Suppose this is your form in aaa.php

<table width="99%"  border="0" cellspacing="0" cellpadding="0">
          <th width="5%" height="62" scope="col">&nbsp;</th>
          <th width="51%" align="left" valign="top" scope="col"><form name="form2" method="post" action="aaa.php">
		//here you can view uploaded image
		  <img src="<?php echo $path ?>" height="150" width="150">
          <th width="44%" align="left" valign="top" scope="col"><form action="aaa.php" method="POST" enctype="multipart/form-data">
    <font size="1"></font><br>
    <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
        <td width="246">
          <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
          <input name="userfile" type="file" id="userfile">
        <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>

create uploads folder in your directory and php code do store

$uploadDir = 'uploads/';

	$fileName = $_FILES['userfile']['name'];
	$tmpName = $_FILES['userfile']['tmp_name'];
	$fileSize = $_FILES['userfile']['size'];
	$fileType = $_FILES['userfile']['type'];
	$filePath = $uploadDir . $fileName;

	$result = move_uploaded_file($tmpName, $filePath);
	if (!$result)
	//echo "Error uploading file";
	$fileName = addslashes($fileName);
	$filePath = addslashes($filePath);

	$query = "update table set path='$filePath' where user_id='$user_id'";//change query according to you
	mysql_query($query) or die('Error, query failed');
	//echo "<br>File $fileName uploaded<br>";

create column path in your store path of image in database...which is in uploads folder

Thank you for the Code it works fine))
the problem comes when displaying the photos,so do i display them?
Also how do i save to database?bcoz i saved as varchar when i upload the photo i saw the whole link in my db.
when i saved as longblob i just saw the bait-34(a certain number))
thank you))

Suppose you have to display image which is uploaded for user1

//change query according to your table structure, column names
 $sql=mysql_query("SELECT * FROM table where user_fname='$user_fname'");
		  $row = mysql_fetch_array($sql);
		  $path=$row['path'];//here you get path where you store image for user1

In table you have to write like

<table width="100%" style="height:157%"  border="0" cellpadding="0" cellspacing="0">
             <th scope="col" > 
		<img src="<?php echo $path ?>" height="150" width="150">

use like path varchar(30) to store image path in database or change size according to you

I think it solves your problem

Below is how i did)))but image still dont show up only area with width=500 and height=400 with an X.

//database connection routine
// Connecting to a MySql Database
//selecting the path of the image for specific user
 $sql=mysql_query("SELECT * FROM picha where user='$user'");
		  $row = mysql_fetch_array($sql);
		  $path=$row['path'];//here you get path where you store image for user1
echo"<font color=blue> filename:$filename Usename: $user_fname<br></font>";// Display  original filename and username

	<img src=<?php echo"$path";?> width=500 height=400>	<br>		  

	echo"$path";	//here i just tried to view the file path	  

after trying to view the file path it shows
where i`m i getting wrong???

Confirm the filename and check if the file is getting properly uploaded.. check the path...

To show image img syntax is

<img src="" height="" width="">


<img src=<?php echo"$path";?> width=500 height=400>//wrong

i mentioned in earlier post (5)also ....
so do like that

<img src="<?php echo $path ?>" height="500" width="400">

Hi I have followed all the steps and I understand the concept behind uploading and displaying an image, however the image still does not display for me.

I believe the problem is with the rights of the file or something. The reason why I think so is because i have tried uploading an image to the "uploads" folder with ftp and i can easily display it however if i upload the same exact image with the upload form and then i try to view it I get the following message "403 Forbidden".

If it makes any difference I am using a hosted site.

Any idea why when i upload an image with the upload form it becomes forbidden in the folder?

Thank Sir .. I have learn your method and Can upload image successfully!!! :D

This article has been dead for over six months. Start a new discussion instead.