| | |
Saving mage in a path instead of storing the real image in mysql
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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...
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...
•
•
Join Date: Apr 2008
Posts: 293
Reputation:
Solved Threads: 11
Suppose this is your form in aaa.php
create uploads folder in your directory and php code do store
create column path in your database...to store path of image in database...which is in uploads folder
PHP Syntax (Toggle Plain Text)
<table width="99%" border="0" cellspacing="0" cellpadding="0"> <tr> <th width="5%" height="62" scope="col"> </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"> </form></th> <th width="44%" align="left" valign="top" scope="col"><form action="aaa.php" method="POST" enctype="multipart/form-data"> <p><br> <font size="1"></font><br> <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> <tr> <td width="246"> <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> <input name="userfile" type="file" id="userfile"> </td> <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td> </tr> </table> <p><br> </form></th> </tr> </table>
create uploads folder in your directory and php code do store
PHP Syntax (Toggle Plain Text)
$uploadDir = 'uploads/'; if(isset($_POST['upload'])) { $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"; $filePath="uploads/no_images.jpeg"; } if(!get_magic_quotes_gpc()) { $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'); $path=$filePath; //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.
•
•
Join Date: Apr 2008
Posts: 293
Reputation:
Solved Threads: 11
Suppose you have to display image which is uploaded for user1
display.php
In table you have to write like
use like path varchar(30) to store image path in database or change size according to you
I think it solves your problem
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
PHP Syntax (Toggle Plain Text)
<table width="100%" style="height:157%" border="0" cellpadding="0" cellspacing="0"> <tr> <th scope="col" > <img src="<?php echo $path ?>" height="150" width="150"> </th> </tr> </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.
•
•
Join Date: Mar 2008
Posts: 217
Reputation:
Solved Threads: 4
Below is how i did)))but image still dont show up only area with width=500 and height=400 with an X.
after trying to view the file path it shows
c:/wamp/www/photo/uploads/Nicwa.jpg
where i`m i getting wrong???
php Syntax (Toggle Plain Text)
<?php //database connection routine // Connecting to a MySql Database include"config.php"; $user='peacemaker'; //selecting the path of the image for specific user $sql=mysql_query("SELECT * FROM picha where user='$user'"); $row = mysql_fetch_array($sql); $user=$row['user']; $filename=$row['filename']; $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> <?php echo"$path"; //here i just tried to view the file path ?>
after trying to view the file path it shows
c:/wamp/www/photo/uploads/Nicwa.jpg
where i`m i getting wrong???
•
•
Join Date: Apr 2008
Posts: 293
Reputation:
Solved Threads: 11
To show image img syntax is
not i mentioned in earlier post (5)also ....
so do like that
PHP Syntax (Toggle Plain Text)
<img src="" height="" width="">
PHP Syntax (Toggle Plain Text)
<img src=<?php echo"$path";?> width=500 height=400>//wrong
so do like that
PHP Syntax (Toggle Plain Text)
<img src="<?php echo $path ?>" height="500" width="400">
Last edited by Aamit; Dec 18th, 2008 at 8:38 am.
•
•
Join Date: May 2009
Posts: 1
Reputation:
Solved Threads: 0
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?
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?
![]() |
Other Threads in the PHP Forum
- Previous Thread: Restrict Image not to cache
- Next Thread: fopen problem
| Thread Tools | Search this Thread |
advanced apache api array basics beginner binary broken cakephp checkbox class cms code combobox cookies cron curl database date datepart display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google head href htaccess html if...loop image include includingmysecondfileinthechain insert ip javascript job joomla jquery key library limit link login mail menu mlm multiple mysql oop password paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search server sessions smarty sms sorting source space sql stored syntax system table traffic tutorial unicode update upload url validator variable video web youtube zend





