/    Sign up×
Community /Pin to ProfileBookmark

Image upload in mysql

Hi there,
I want to know the simplest way to upload an image in to the database using php and display it back to my web page.If any one has the simplest code then please share it with me.

Thank You?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@FSDesignsAug 02.2012 — It's easy.

PHP page allowing the image file to be uploaded to an uploads directory. (Ensure its a valid image file and not a shell script that could allow hackers backdoor access to your site).

Once image is validated as true image. Store location of image in database. (e.g. - "images/image_file_name.jpg")

then call it through the display.php page in the <img src="$img" />

(keep in mind you have to run an SQL query to fetch the image location with a unique ID and attach it to the variable called $img.
Copy linkTweet thisAlerts:
@ssystemsAug 02.2012 — If you want to store the actual data in the database take this as a sample http://stackoverflow.com/questions/6048600/save-image-as-a-blob-type
Copy linkTweet thisAlerts:
@manjuhugar24authorAug 03.2012 — Thank you both of you ..?
Copy linkTweet thisAlerts:
@FSDesignsAug 03.2012 — Thank you both of you ..?[/QUOTE]

Anytime mate ?
Copy linkTweet thisAlerts:
@mahfoozAug 07.2012 — [code=php]
$tempFileName = $_FILES['attachFile']['tmp_name'];
$file = fopen($tempFileName, 'r');
$content = fread($file, filesize($tempFileName));
$encryptedContent = base64_encode($content);
[/code]


you can store $encryptedContent in database, and when you want this image to display on webpage, simply use base64_decode(dbcolumn)

enjoy man
×

Success!

Help @manjuhugar24 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...