Results 1 to 3 of 3
Thread: php script to upload images
-
07-03-2005, 10:22 AM #1Junior Guru
- Join Date
- Mar 2005
- Posts
- 214
hummn
How do i make a php script to upload images in the best way, i know how from tutorials but i want to know which way is best and why cause i want efficiancy and stuff, there is a simple way i know of that i like:
save into database image code
<?php
/*get file from
pc*/
include("db.php");
$FILE = $_POST[file_url];
if($FILE == FALSE || $NAME== FALSE) {
echo "NO FILE WAS SELECTED!";
}
else {
mysql query("INSERT INTO images(img_code, img_name) VALUES('$FILE', '$NAME')", $db);
}
?>
generate image from database
<?php
/*read image from
database*/
include("db.php");
$image=$_GET[image];
if($image==TRUE) {
header("Content-type: image/gif");
$image_query = mysql_query("SELECT img_code FROM images WHERE img_name='$image'", $db);
$image_code = mysql_fetch_array($image_query);
echo "$image_code";
}
?>
but is that a good way to use
-
07-03-2005, 05:19 PM #2Web Hosting Master
- Join Date
- Jun 2004
- Location
- Bay Area -USA
- Posts
- 1,740
If it works - it looks pretty good.
I would just leave it.<<< Please see Forum Guidelines for signature setup. >>>
-
07-03-2005, 05:51 PM #3Hail Eris !
- Join Date
- Oct 2002
- Location
- Canada
- Posts
- 3,103
PHP Code:if ( is_uploaded_file($_FILES['Filen_Name']['tmp_name']) && $image_details = @getImageSize($_FILES['File_Name']['tmp_name']) && $image_details[2] == '2' ) { // just for an example we tested if image is JPEG
$img = file_get_contents($_FILES['File_Name']['tmp_name']) ;
$query = "INSERT INTO images (original_name, size , width, height, img) VALUES (
'".addslashes($_FILES['File_Name']['name'])."' ,
'".strlen($img)."' , '".$image_details[0]."' , '".$image_details[1].'" , '".addslashes($img)."') " ;
.....
This way we can do one read, and have all image details we might need ready to use.