...

View Full Version : image uploading problem



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...:(

esthera
08-10-2005, 06:58 PM
does the asp server support aspupload?

Otherwise search in google pureasp upload and you'll see many examples.

mivec
08-10-2005, 07:16 PM
does the asp server support aspupload?

Otherwise search in google pureasp upload and you'll see many examples.

i am not too sure though...coz i am trying to make it work locally with IIS first. then just upload it to the server later and it also will work....i know, i have went through many COM components and others but it just doesn't seem to work and i don't know y it doesnt.....sigh.... :(

neocool00
08-10-2005, 07:42 PM
http://www.asp101.com/articles/jacob/scriptupload.asp

This will have everything you need.

mivec
08-10-2005, 07:48 PM
http://www.asp101.com/articles/jacob/scriptupload.asp

This will have everything you need.

went there already...i dun think it will work...and i dun really understand what it says......****...i am so noob in asp!!!

:(

Bullschmidt
08-11-2005, 01:15 AM
And here is another pure ASP (i.e. no components) resource which I've used for letting the user upload a file which is something that was unfortunately not built into ASP:

ASP File Upload Using VBScript by John R. Lewis - 7/10/2000
http://aspzone.com/articles/160.aspx

Oops I think this is the same article as the previous post just on two different sites...

[LATER EDIT] Actually they are 2 different articles by 2 different people.

mivec
08-11-2005, 05:48 AM
And here is another pure ASP (i.e. no components) resource which I've used for letting the user upload a file which is something that was unfortunately not built into ASP:

ASP File Upload Using VBScript by John R. Lewis - 7/10/2000
http://aspzone.com/articles/160.aspx

Oops I think this is the same article as the previous post just on two different sites...

wow....the wordings are like so hard to see....i couldn't even bother to look further...grey background with white fonts!....damn....my eyes actually is starting to hurt......and i dun think it will work too....wow.....i hv been trying to do this for two days and still to no avail....getting desperate...does anyone have his/her script that he/she had used before that works?

:(

mivec
08-11-2005, 07:02 AM
ok...maybe it will be easier if someone knows the keywords of these php to asp:

1)mkdir
2)!in_array
3)!file_exists
4)$_FILES['file']['tmp_name'], $_FILES['file']['size']
5)!isset
6)date("YmdHis")
7)copy

if someone can tell me these reserved words of php to asp, then i think i know what to do....pls help...thanks :( :( :(

neocool00
08-11-2005, 04:43 PM
@mivec,
Both articles that Bull and I pointed to have options to download the source code. And I agree with you, white text on a grey background is murder, not sure who did that one :eek:. However, if you hi-light the text in the boxes, you'll see the code in a more "readable" format. Both articles take the same approach. They use "classes" so that the code on your form & result page is simple. As a FYI, classes come from object oriented programming. Although I don't think ASP was originally designed to handle OOP, there are ways that you can do it (and those articles are good examples). But that is a whole nother discussion. The best thing to do is download the source code files, stick them on your server and start playing with them and then go from there.

mivec
08-11-2005, 05:51 PM
The best thing to do is download the source code files, stick them on your server and start playing with them and then go from there.

yup u got that right....but somehow, i just dun see any code that will work for my part.....i wonder who has done any and may be kind enuf to share it wid me....i did it in php before but am a total noob in asp.... :(

neocool00
08-11-2005, 09:33 PM
So let me see if I got this right.

1) You have a multi-part form that allows a user to upload a file.
2) On submit, you want to upload the file to a specified location on the web server.
3) The path to the file needs to be stored in an existing database.

Anything I'm missing?

mivec
08-11-2005, 10:23 PM
So let me see if I got this right.

1) You have a multi-part form that allows a user to upload a file.
2) On submit, you want to upload the file to a specified location on the web server.
3) The path to the file needs to be stored in an existing database.

Anything I'm missing?

yo...u read my mind dude.....thats what i need....



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum