mivec
08-10-2005, 03:57 PM
hi all,
i am using asp to upload pictures to the database. only thing is, i am definitely not uploading the picture itself to the db as that's just insane, instead i plan to just upload the path of the image that has been uploaded. i am not too sure how to do it in asp but in php, i hv done it before and i just can't figure out how to do it for asp.
in my previous php upload image code:
//check image function
function checkfile($inputname,$inputsize,$inputtype,$size){
global $error;
if($inputsize==0){
$error="Please select a picture for your product!";
}
elseif($inputsize>$size){
$error="File size can be maximum ".$size." bytes!";
}
elseif(is_uploaded_file($inputname)){
$file_type=$inputtype;
$allowed_types=array("image/bmp","image/gif","image/pjpeg","image/jpeg");
if(!in_array($file_type, $allowed_types))
$error="File type not permitted! (Please use jpg, jpeg, bmp, or gif images)";
}
}
<?
if(!file_exists("images/newsEvents") && !file_exists("images/Thumbnails")){
mkdir("images/newsEvents");
mkdir("images/Thumbnails");
}
$uploaddir = "images/newsEvents/";
$uploadthumb = "images/Thumbnails/";
// check file call function
checkfile($_FILES['file']['tmp_name'], $_FILES['file']['size'], $_FILES['file']['type'],35000);
else:
// copy file if no error occured
if(!isset($error) && !isset($err)){
$date = date("YmdHis");
$done = copy($_FILES['file']['tmp_name'],$uploaddir.$date.'.jpg');
$done2 = copy($_FILES['file']['tmp_name'],$uploadthumb.$date.'.jpg');
}
if (($done) && ($done2)){
$query = "INSERT INTO tblNews (title,date,contents,image,imageAlign,thumbnail,newsType) VALUES ('" . addslashes($_POST["txtEvetitle"]) . "','" . addslashes($date) . "','" . addslashes($_POST["txtaDescription"]) . "','" . addslashes($uploaddir) . $date . ".jpg','" . ($_POST["radAlign"]) . "','" . addslashes($uploadthumb) . $date . ".jpg','" . ($_POST["radNewsType"]) . "')";
mysql_query($query) or
die (mysql_error());
echo "Upload Successful! You Will Be Redirected Back To The Main Page In 5 Seconds<br>
Or <a href=http://artisticsoft/halo/index.php>Click Here</a> To Return to the Previous Page. ";
}
else{
echo "Upload Failed!";
}
endif;
?>
there we have it...i hope it's not a boredom to u all...it's just that i dunno the key words of isset, addslahses, in_array...etc..etc. so can anyone guide me no how to translate the php code above to asp??? very lost here...:(
i am using asp to upload pictures to the database. only thing is, i am definitely not uploading the picture itself to the db as that's just insane, instead i plan to just upload the path of the image that has been uploaded. i am not too sure how to do it in asp but in php, i hv done it before and i just can't figure out how to do it for asp.
in my previous php upload image code:
//check image function
function checkfile($inputname,$inputsize,$inputtype,$size){
global $error;
if($inputsize==0){
$error="Please select a picture for your product!";
}
elseif($inputsize>$size){
$error="File size can be maximum ".$size." bytes!";
}
elseif(is_uploaded_file($inputname)){
$file_type=$inputtype;
$allowed_types=array("image/bmp","image/gif","image/pjpeg","image/jpeg");
if(!in_array($file_type, $allowed_types))
$error="File type not permitted! (Please use jpg, jpeg, bmp, or gif images)";
}
}
<?
if(!file_exists("images/newsEvents") && !file_exists("images/Thumbnails")){
mkdir("images/newsEvents");
mkdir("images/Thumbnails");
}
$uploaddir = "images/newsEvents/";
$uploadthumb = "images/Thumbnails/";
// check file call function
checkfile($_FILES['file']['tmp_name'], $_FILES['file']['size'], $_FILES['file']['type'],35000);
else:
// copy file if no error occured
if(!isset($error) && !isset($err)){
$date = date("YmdHis");
$done = copy($_FILES['file']['tmp_name'],$uploaddir.$date.'.jpg');
$done2 = copy($_FILES['file']['tmp_name'],$uploadthumb.$date.'.jpg');
}
if (($done) && ($done2)){
$query = "INSERT INTO tblNews (title,date,contents,image,imageAlign,thumbnail,newsType) VALUES ('" . addslashes($_POST["txtEvetitle"]) . "','" . addslashes($date) . "','" . addslashes($_POST["txtaDescription"]) . "','" . addslashes($uploaddir) . $date . ".jpg','" . ($_POST["radAlign"]) . "','" . addslashes($uploadthumb) . $date . ".jpg','" . ($_POST["radNewsType"]) . "')";
mysql_query($query) or
die (mysql_error());
echo "Upload Successful! You Will Be Redirected Back To The Main Page In 5 Seconds<br>
Or <a href=http://artisticsoft/halo/index.php>Click Here</a> To Return to the Previous Page. ";
}
else{
echo "Upload Failed!";
}
endif;
?>
there we have it...i hope it's not a boredom to u all...it's just that i dunno the key words of isset, addslahses, in_array...etc..etc. so can anyone guide me no how to translate the php code above to asp??? very lost here...:(