Uploading images and saving into sql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
killingbegin
Forum Newbie
Posts: 20
Joined: Sun Feb 08, 2009 5:07 am

Uploading images and saving into sql

Post by killingbegin »

Anyone that can link how to upload an save an image in an sql server?
Propably you can save the path and sabve the foto on a folder that you want but anyway whats the way?
And resizing your photos?
I serached lot to find that but didnt find anything ty
Deuce
Forum Newbie
Posts: 12
Joined: Sun Jan 25, 2009 5:23 pm

Re: Uploading images and saving into sql

Post by Deuce »

As far as resizing, I really like the TimThumb script http://www.darrenhoyt.com/2008/04/02/ti ... -released/

Uploading, you can either use a BLOB and keep the binary data in the database - which can lead to a hefty DB size.
Or you can just upload it with a simple upload script - here is an example to get you started - http://www.tizag.com/phpT/fileupload.php

and just save the file path to the database and then just out the file path which is what I would recommend.
User avatar
dheeraj
Forum Commoner
Posts: 40
Joined: Fri Feb 06, 2009 11:54 am

Re: Uploading images and saving into sql

Post by dheeraj »

try below stuff i think u'll get wht u want...

say upload.php

Code: Select all

<form action="confirm_show.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<input name="ufile" type="file" id="ufile" size="29" />
<input type="submit" name="Submit" value="Submit" />
</form>
 
confirm_up.php

Code: Select all

<?php
 
// Your file name you are uploading
$file_name = $HTTP_POST_FILES['ufile']['name'];
 
// random 4 digit to add to our file name
// some people use date and time in stead of random digit
$random_digit=rand(0000,9999);
 
//combine random digit to you file name to create new file name
//use dot (.) to combile these two variables
 
$new_file_name=$random_digit.".jpg";
 
//set where you want to store files
//in this example we keep file in folder upload
//$new_file_name = new upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= "upload/".$new_file_name;
$check=0;
if($ufile !=none)
{
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
    echo "File Name : ".$new_file_name;
}
else
{
    echo "Error";
}
}
?>
Note: Its changing the file name also
killingbegin
Forum Newbie
Posts: 20
Joined: Sun Feb 08, 2009 5:07 am

Re: Uploading images and saving into sql

Post by killingbegin »

Thanx lot guys rly hellpfull.
I just saved into my DB the path of the image and 'GG'.

also for the resizing code.
Tip make a upload form that you will get only the name of the image and echo

<img src="/scripts/timthumb.php?src=/images/whatever.jpg&h=150&w=150&zc=1" alt="" />

at the whatever.jpg the name will be your pic name.and etc

Gj ty
Post Reply