Image Upload Function (Advanced) (w/ resize)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Sybatical
Forum Newbie
Posts: 7
Joined: Mon Mar 29, 2004 4:54 pm

Image Upload Function (Advanced) (w/ resize)

Post by Sybatical »

I recently download the above script at Evil Walrus

But having trouble getting it to work. -_-
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

uhm... ok.... What 'trouble' are you having?
Sybatical
Forum Newbie
Posts: 7
Joined: Mon Mar 29, 2004 4:54 pm

Post by Sybatical »

I upload the file and nothing shows up.

Eg. Here
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

uhh... most likely if you download a script, theres going to be a few things taht your going to have to edit to work on your server. have you edited anything at all?? Or did you just download that script and upload it to your server and don't know anything about php to fix anything?? and why did you name it +resize).php??
Sybatical
Forum Newbie
Posts: 7
Joined: Mon Mar 29, 2004 4:54 pm

Post by Sybatical »

Not new to php.
<?PHP
function image_upload($userfile, $newfile, $directory, $width, $height, $quality='100', $smooth='10', $extention='AUTO') {
$imgsize = GetImageSize($userfile);
if (($imgsize[0] > $width) || ($imgsize[1] > $height)) {
$tmpimg = tempnam("/tmp", "MKUP");
system("djpeg $userfile >$tmpimg");
system("pnmscale -xy $width $height $tmpimg | cjpeg -smoo $smooth -qual $quality >$userfile");
unlink($tmpimg);
};
$mimetype = $_FILES['userfile']['type'];

if ($extention == "AUTO") {
if (($mimetype == "image/x-png") || ($mimetype == "image/png")){
$extention = "png";
}elseif ($mimetype == "image/pjpeg"){
$extention = "jpg";
}elseif ($mimetype == "image/gif"){
$extention = "gif";
}else{
$extention = "";
$error_message = "Please upload images with the extension .jpg or .jpeg or .gif or .png only";
};
};
if (strstr($mimetype, "image/")) {
$newfile_name = $newfile.".".$extention;
$newfile = $directory.$newfile_name;
if (is_uploaded_file($userfile)){
if (!copy($userfile, $newfile)) {
$error_message = "Error Uploading File.";
};
};
return $newfile_name;
}else{
$error_message = "Not An Image";
};
};

//EXAMPLE

image_upload($_FILE['userfile'], "Avatar-123", "images/avatars/", 90, 90, 100, 0)
?>
Cant work how to fix it. I cant see any MySQL tags etc

Oh and +resize) is the downloaded name
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

LOL, no wonder nothign comes up. Nothing is supposed to. All that is, is an upload and resize function. You have to write everythign else - like the form.....
Sybatical
Forum Newbie
Posts: 7
Joined: Mon Mar 29, 2004 4:54 pm

Post by Sybatical »

Damn! I new something was wrong! :P
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

and you dont need this in there its just an example

Code: Select all

<?php
//EXAMPLE

image_upload($_FILE['userfile'], "Avatar-123", "images/avatars/", 90, 90, 100, 0)
?>
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

Sybatical wrote:Not new to php.
If your not a n00b, i think you would have noticed that all that is is a function, and nothing will show up unless you build an application around that function. And if you don't know anything about functions and/or forms and/or php, i would suggest go and reading some tutorials and trying small things on your own, and not just downloading scripts and asking why they dont work.
Sybatical
Forum Newbie
Posts: 7
Joined: Mon Mar 29, 2004 4:54 pm

Post by Sybatical »

The description said nothing about function.
function image_upload($userfile, $newfile, $directory, $width, $height, $quality='100', $smooth='10', $extention='AUTO') {
I should have looked at it first.

I think I'll take the avatar browser from a phpbb forum. ;)
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

I should have looked at it first.
That just shows that you are a n00b and don't know what your doing. Someone who knows PHP or any programnming language and wants to learn more will take the time to learn it. But its people like you that all you do is take other's scripts that look nice, ask for help to get them to work, call them yours, and never learn anything.
Sybatical
Forum Newbie
Posts: 7
Joined: Mon Mar 29, 2004 4:54 pm

Post by Sybatical »

Thats the first script i have actually downloaded. O.o

I asked for help, not to be flamed.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Most of those open source ones are posted with little or no documentation. The author pretty much intends the snipplet of code to be used by a more experienced user of the language.

You shouldn't feel bad making a mistake while you're learning, no big deal there. I'm sure everyone has, and it's good that you do make mistakes. That way you will know what not to do, and how to do it better next time.

Illusionist: You should be a bit more tollerant to newbie mistakes, no matter how embarrassing/obvious they are. I'm sure you made them too, so ease up a bit. Sheesh.
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

i don't understand why ppl have to be so bad against newbies, just like ppl are in high school against the freshmen, YOU WERE ONE TOO. Maybe somebody treated you that way when you were a noob, geez...

And also, for you people that are really newbies into any kind of subject/matter, stop saying you are a newbie and you don't know anything! because, u might get stuck with the noob thing... and then u will need another nickname to disguise ;)
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

Well, it bugs me how he says he wasn't a n00b, but it was obvious he was...
Post Reply