![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Dec 2004
Posts: 1
Rep Power: 0
![]() |
I need help setting up a form to upload files directly to a server through the website. Thanks.
|
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() |
Here, this is some code i got off www.evilwalrus.com. I havn't used it, but i plan on trying it out soon. Let me know how it works.
Image Upload Function (Advanced) (w/ resize) An advanced form of image uploading. When image is uploaded, it returns the images name. // Userfile = The file // Newfile = The final filename // Directory = The directory to upload to // Width = Maximum width // Height = Maximum height // Quality = JPG style Quality ( 1 - 100 ) // Smooth = How much it blurs on resize // Extention = End file extention (JPG, PNG, GIF) ENJOY! <?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)
?>Good luck, let me know if it works.
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
#3 |
|
Programming Guru
![]() |
That code is linux dependent i believe becasue of the system() calls.
__________________
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() |
most likly. However, it wouldn't take toomuch work to switch it...i recon.
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
#5 |
|
Programming Guru
![]() |
Nah, not much, it would have been ALOT more efficent to write the image resizing using the built in GD library. That way it could be platform independent.. PHP/Windows doesnt support system() functions and the like (they say they do, but they are liars... all liars).
__________________
|
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() |
I didn't write that code, it's off of evilwalrus.com....but you are right.
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
#7 |
|
Programming Guru
![]() ![]() ![]() |
I do this on my boxes at home... when I get off work, I'll post the code that I use.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|