Image Upload Function (Advanced) (w/ resize)
Moderator: General Moderators
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
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??
Not new to php.
Oh and +resize) is the downloaded name
Cant work how to fix it. I cant see any MySQL tags etc<?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)
?>
Oh and +resize) is the downloaded name
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
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
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 wrote:Not new to php.
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
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.I should have looked at it first.
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.
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
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
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