Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 2nd, 2004, 1:39 PM   #1
DJCyto
Newbie
 
Join Date: Dec 2004
Posts: 1
Rep Power: 0 DJCyto is on a distinguished road
I need help setting up a form to upload files directly to a server through the website. Thanks.
DJCyto is offline   Reply With Quote
Old Dec 2nd, 2004, 3:01 PM   #2
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
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!
Pizentios is offline   Reply With Quote
Old Dec 2nd, 2004, 11:00 PM   #3
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
That code is linux dependent i believe becasue of the system() calls.
__________________

tempest is offline   Reply With Quote
Old Dec 2nd, 2004, 11:50 PM   #4
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
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!
Pizentios is offline   Reply With Quote
Old Dec 2nd, 2004, 11:55 PM   #5
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
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).
__________________

tempest is offline   Reply With Quote
Old Dec 3rd, 2004, 12:02 AM   #6
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
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!
Pizentios is offline   Reply With Quote
Old Dec 3rd, 2004, 12:40 PM   #7
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:42 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC