Image Uploads


#1

Hi, can you help please! i have looked arround for tutorials about uploading images using php. They are very complicated or incomplete, can anyone link me to a good tutorial or give me the basics? thank you!


#2

[code]<?php
//check for required fields from the form
if (!$_POST[‘faqTitle’]){
header(“Location: faq_add.php”);
exit;
}

//all values for the uploading method
$UPLOAD_SIZE['max']=5000000;
$UPLOAD_SIZE['min']=0;

//start checking the upload
$file_dir="/home/admin/httpd/html/upload/";

$result=verify_upload($_FILES['upload_files']['size']);

function verify_upload($intSize){
	//check file size
	if($intSize < $GLOBALS['UPLOAD_SIZE']['min'] || $intSize > $GLOBALS['UPLOAD_SIZE']['max'])
	{
		return -1;
	}
	   
	return 1;
}

$filename = $_FILES['upload_files']['name'];
$upload = $_FILES['upload_files']['tmp_name'];

$newdir = $file_dir . $filename;
	
$conn =mysql_connect("localhost","root","")
	or die ("Unable to connect to database.");
mysql_select_db("knowledgebase",$conn)
	or die ("Database Does Not Exist");

$sql="SELECT * from FAQ";

if(mysql_query($sql,$conn) ){
	if($result != 1){
		die("File size out of allowed range");
	}
	else{
		if(empty($filename)){
			$sql2="INSERT INTO FAQ VALUES ('','$_POST[faqTitle]', '$_POST[faqQuest]', '$_POST[faqAns]', '$filename','1',now())";
			mysql_query($sql2,$conn) or die (mysql_error());
			#echo "SUCCESSFULL";
			include ("faq_add.php");
		}
		else{
			move_uploaded_file($upload,"$newdir")
				or die ("Couldn't upload the file");
			$sql2="INSERT INTO FAQ VALUES ('','$_POST[faqTitle]', '$_POST[faqQuest]', '$_POST[faqAns]', '$filename','1',now())";
			mysql_query($sql2,$conn) or die (mysql_error());
			#echo "SUCCESSFULL";
			include ("faq_add.php");
		}
	}
}
else{
	echo "ERROR";
	include("faq_add.php");
}

?>[/code]

dont know whether this is helping or not…but for me its working…
but its not just for image… its for any type of file…
altered from SAMS books…


#3

Maybe this will help ya… it is a tutorial

http://codewalkers.com/tutorials/35/1.html