Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET GimmeCode
Hi,
please give me the below sample code is in php convert it into c# code.
code starts here:
 
$ratio2)    {
          $thumb_w=$new_w;
          $thumb_h=$old_y/$ratio1;
        }
        else    {
          $thumb_h=$new_h;
          $thumb_w=$old_x/$ratio2;
        }
          // we create a new image with the new dimmensions
        $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
        // resize the big image to the new created one
        imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
        // output the created image to the file. Now we will have the thumbnail into the file named by $filename
        if(!strcmp("png",$ext))
          imagepng($dst_img,$filename);
        else
          imagejpeg($dst_img,$filename);
 
          //destroys source and destination images.
        imagedestroy($dst_img);
        imagedestroy($src_img);
       }
       function getExtension($str) {
               $i = strrpos($str,".");
               if (!$i) { return ""; }
               $l = strlen($str) - $i;
               $ext = substr($str,$i+1,$l);
               return $ext;
       }
 
        //reads the name of the file the user submitted for uploading
       $image=$_FILES[$fileElementName]['name'];
 
    // if it is not empty
    if ($image)
    {
        // get the original name of the file from the clients machine
        $filename = stripslashes($_FILES[$fileElementName]['name']);
 
        // get the extension of the file in a lower case format
        $extension = getExtension($filename);
        $extension = strtolower($extension);
        // if it is not a known extension, we will suppose it is an error, print an error message
        //and will not upload the file, otherwise we continue
        if (($extension != "jpg")  && ($extension != "jpeg") && ($extension != "png"))
        {
            $error .= 'Unknown extension!';
            $errors=1;
        }
        else
        {
            
            $size=getimagesize($_FILES[$fileElementName]['tmp_name']);
            $sizekb=filesize($_FILES[$fileElementName]['tmp_name']);
 
            //compare the size with the maxim size we defined and print error if bigger
            if ($sizekb > MAX_SIZE*1024)
            {
                $error .= 'You have exceeded the size limit!';
                $errors=1;
            }
            else {
 
              //we will give an unique name, for example the time in unix time format
            $image_name=time().'.'.$extension;
            //the new name will be containing the full path where will be stored (images folder)
            $newname="/images/masters/".$image_name;
            $copied = copy($_FILES[$fileElementName]['tmp_name'], $newname);
            //we verify if the image has been uploaded, and print error instead
            if (!$copied)
            {
              $error .= 'Copy unsuccessfull!';
              $errors=1;
            }
            else
            {
              // the new thumbnail image will be placed in images/thumbs/ folder
              $thumb_name='/images/thumbs/thumb_'.$image_name;
              // call the function that will create the thumbnail. The function will get as parameters
              //the image name, the thumbnail name and the width and height desired for the thumbnail
              $thumb=make_thumb($newname,$thumb_name,40,40);
 
              //also add the users pic
              $thumb_name='/images/thumbs/thumb_'.$image_name;
              $thumb=make_thumb($newname,$thumb_name,110,110);
 
            }}
        }
            }
 
      //--------- END SECOND SCRIPT --------------------------------------------------------------------

      //return variables to javascript
            $filename = $_FILES[$fileElementName]['name'];
            $filesize = round(($sizekb/1000), 0);
            $fileloc = $thumb_name;
            //for security reason, we force to remove all uploaded file
            @unlink($_FILES[$fileElementName]);
    }
    $return_JSON = "";
    $return_JSON .= "{";
    $return_JSON .=             "error: '" . $error . "',\n";
    $return_JSON .=             "name: '" . $filename . "',\n";
    $return_JSON .=             "size: '" . $filesize . "',\n";
    $return_JSON .=             "loc: '" . $fileloc . "'\n";
    $return_JSON .= "}";
    echo $return_JSON;
?>
Posted 2-Sep-13 23:33pm
Edited 3-Sep-13 11:38am
Nelek68.5K
v3
Comments
Madhugundi at 3-Sep-13 4:35am
   
please refer the below link
http://www.jquery4u.com/tutorials/thumbnail-image-upload-ajaxphp/
jkirkerx at 3-Sep-13 17:16pm
   
I wouldn't convert it, just write a new one in c#
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This is not how CP usually works. Most important goal here is to learn and help learning.
You are supposed to try it on your own, and come here when you got stuck with something, with a concrete question about your code, design, etc.
Please have a look to What have you tried?[^] to see a good explanation about what I mean.
Don't forget people here don't get payed. And besides, if we give you a ready-to-go solution, it is not going to help you because you are not going to learn anything from it.
 
P.S. Written as solution to avoid this "question" to be in the unanswered list
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This is the quick answer forum and you will not find anyone to do all of your work for you. I recommend you get started on converting it and if you get stuck on a specific line then please ask.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 260
1 ProgramFOX 165
2 Peter Leow 130
3 Zoltán Zörgő 130
4 Maciej Los 80
0 OriginalGriff 260
1 ProgramFOX 145
2 Peter Leow 130
3 Sergey Alexandrovich Kryukov 85
4 Fredrik Bornander 75


Advertise | Privacy | Mobile
Web01 | 2.8.150301.1 | Last Updated 3 Sep 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100