Saving mage in a path instead of storing the real image in mysql

Reply

Join Date: Mar 2008
Posts: 217
Reputation: mrcniceguy is an unknown quantity at this point 
Solved Threads: 4
mrcniceguy mrcniceguy is offline Offline
Posting Whiz in Training

Saving mage in a path instead of storing the real image in mysql

 
0
  #1
Dec 14th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 94
Reputation: sikka_varun is an unknown quantity at this point 
Solved Threads: 11
sikka_varun's Avatar
sikka_varun sikka_varun is offline Offline
Junior Poster in Training

Re: Saving mage in a path instead of storing the real image in mysql

 
0
  #2
Dec 14th, 2008
Hi..
Check out this tutorial... this will help you...
http://www.htmlgoodies.com/beyond/we...le.php/3548746

When you specify the location to store the images, then its mostly the hard path, for eg. c:\inetputb\wwwroot\mysitename\images...
or
/var/home/sitename/images

So take care of the paths...
VâRûN
---Happy to Help---
sikka_varun@yahoo.com
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 293
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: Saving mage in a path instead of storing the real image in mysql

 
0
  #3
Dec 15th, 2008
Suppose this is your form in aaa.php
  1. <table width="99%" border="0" cellspacing="0" cellpadding="0">
  2. <tr>
  3. <th width="5%" height="62" scope="col">&nbsp;</th>
  4. <th width="51%" align="left" valign="top" scope="col"><form name="form2" method="post" action="aaa.php">
  5. //here you can view uploaded image
  6. <img src="<?php echo $path ?>" height="150" width="150">
  7. </form></th>
  8. <th width="44%" align="left" valign="top" scope="col"><form action="aaa.php" method="POST" enctype="multipart/form-data">
  9. <p><br>
  10. <font size="1"></font><br>
  11. <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
  12. <tr>
  13. <td width="246">
  14. <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
  15. <input name="userfile" type="file" id="userfile">
  16. </td>
  17. <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
  18. </tr>
  19. </table>
  20. <p><br>
  21. </form></th>
  22. </tr>
  23. </table>

create uploads folder in your directory and php code do store
  1. $uploadDir = 'uploads/';
  2.  
  3. if(isset($_POST['upload']))
  4. {
  5.  
  6. $fileName = $_FILES['userfile']['name'];
  7. $tmpName = $_FILES['userfile']['tmp_name'];
  8. $fileSize = $_FILES['userfile']['size'];
  9. $fileType = $_FILES['userfile']['type'];
  10.  
  11. $filePath = $uploadDir . $fileName;
  12.  
  13. $result = move_uploaded_file($tmpName, $filePath);
  14. if (!$result)
  15. {
  16. //echo "Error uploading file";
  17. $filePath="uploads/no_images.jpeg";
  18. }
  19.  
  20. if(!get_magic_quotes_gpc())
  21. {
  22. $fileName = addslashes($fileName);
  23. $filePath = addslashes($filePath);
  24. }
  25.  
  26. $query = "update table set path='$filePath' where user_id='$user_id'";//change query according to you
  27.  
  28. mysql_query($query) or die('Error, query failed');
  29. $path=$filePath;
  30. //echo "<br>File $fileName uploaded<br>";

create column path in your database...to store path of image in database...which is in uploads folder
Last edited by Aamit; Dec 15th, 2008 at 7:16 am.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 217
Reputation: mrcniceguy is an unknown quantity at this point 
Solved Threads: 4
mrcniceguy mrcniceguy is offline Offline
Posting Whiz in Training

Re: Saving mage in a path instead of storing the real image in mysql

 
0
  #4
Dec 16th, 2008
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))
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 293
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: Saving mage in a path instead of storing the real image in mysql

 
0
  #5
Dec 17th, 2008
Suppose you have to display image which is uploaded for user1
display.php
<?php
//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);
		  $user_fname=$row['user_fname'];
		  $pass=$row['user_lname'];
		  $path=$row['path'];//here you get path where you store image for user1
?>

In table you have to write like
  1.  
  2. <table width="100%" style="height:157%" border="0" cellpadding="0" cellspacing="0">
  3. <tr>
  4. <th scope="col" >
  5. <img src="<?php echo $path ?>" height="150" width="150">
  6. </th>
  7. </tr>
  8. </table>

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

I think it solves your problem
Last edited by Aamit; Dec 17th, 2008 at 1:19 am.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 217
Reputation: mrcniceguy is an unknown quantity at this point 
Solved Threads: 4
mrcniceguy mrcniceguy is offline Offline
Posting Whiz in Training

Re: Saving mage in a path instead of storing the real image in mysql

 
0
  #6
Dec 17th, 2008
Below is how i did)))but image still dont show up only area with width=500 and height=400 with an X.

  1. <?php
  2. //database connection routine
  3. // Connecting to a MySql Database
  4. include"config.php";
  5. $user='peacemaker';
  6. //selecting the path of the image for specific user
  7. $sql=mysql_query("SELECT * FROM picha where user='$user'");
  8. $row = mysql_fetch_array($sql);
  9. $user=$row['user'];
  10. $filename=$row['filename'];
  11. $path=$row['path'];//here you get path where you store image for user1
  12. echo"<font color=blue> filename:$filename Usename: $user_fname<br></font>";// Display original filename and username
  13.  
  14. ?>
  15.  
  16. <img src=<?php echo"$path";?> width=500 height=400> <br>
  17.  
  18.  
  19. <?php
  20.  
  21. echo"$path"; //here i just tried to view the file path
  22.  
  23. ?>

after trying to view the file path it shows
c:/wamp/www/photo/uploads/Nicwa.jpg
where i`m i getting wrong???
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 94
Reputation: sikka_varun is an unknown quantity at this point 
Solved Threads: 11
sikka_varun's Avatar
sikka_varun sikka_varun is offline Offline
Junior Poster in Training

Re: Saving mage in a path instead of storing the real image in mysql

 
0
  #7
Dec 17th, 2008
Hi..
Confirm the filename and check if the file is getting properly uploaded.. check the path...
VâRûN
---Happy to Help---
sikka_varun@yahoo.com
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 293
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: Saving mage in a path instead of storing the real image in mysql

 
0
  #8
Dec 18th, 2008
To show image img syntax is
  1. <img src="" height="" width="">
not
  1. <img src=<?php echo"$path";?> width=500 height=400>//wrong
i mentioned in earlier post (5)also ....
so do like that
  1. <img src="<?php echo $path ?>" height="500" width="400">
Last edited by Aamit; Dec 18th, 2008 at 8:38 am.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 1
Reputation: ssuave is an unknown quantity at this point 
Solved Threads: 0
ssuave ssuave is offline Offline
Newbie Poster

Re: Saving mage in a path instead of storing the real image in mysql

 
0
  #9
May 31st, 2009
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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC