如何将PHP代码转换为mvc3或c# [英] how to convert php code to mvc3 or c#

查看:52
本文介绍了如何将PHP代码转换为mvc3或c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



请给我以下示例代码在php中将其转换为c#代码。

代码从这里开始:

< pre lang =PHP> $ ratio2){
$ thumb_w = $ new_w;
$ thumb_h = $ old_y / $ ratio1;
}
else {
$ thumb_h = $ new_h;
$ thumb_w = $ old_x / $ ratio2;
}
// 我们使用新的dimmensions创建新图片
$ dst_img = ImageCreateTrueColor($ thumb_w,$ thumb_h);
// 将大图像调整为新创建的图像
imagecopyresampled($ dst_img,$ src_img,0,0,0,0,$ thumb_w,$ thumb_h,$ old_x,$ old_y);
// 将创建的图像输出到文件。现在我们将缩略图放入由$ filename
命名的文件中(如果(!strcmp( png,$ ext))
imagepng($ dst_img,$ filename);
else
imagejpeg($ dst_img,$ filename);

// 销毁源图像和目标图像。
imagedestroy( $ dst_img);
imagedestroy($ src_img);
}
函数getExtension($ str){
$ i = strrpos($ str, );
if(!$ i){ return ; }
$ l = strlen($ str) - $ i ;
$ ext = substr($ str,$ i + 1,$ l);
返回 $ ext ;
}

// 读取用户提交上传的文件的名称
$ image = $ _ FILES [$ fileElementName] [' name'] ;

// 如果它不为空
if ($ image)
{
// 从客户端计算机获取文件的原始名称
$ filename = stripslashes($ _ FILES [$ fileElementName] [' name']);

// 以小写格式获取文件的扩展名
$ extension = getExtension($ filename);
$ extension = strtolower($ extension);
// 如果它不是已知的扩展名,我们会认为这是一个错误,打印错误信息
// 并且不会上传文件,否则我们会继续
if (($ extension!= jpg )&&($ extension!= jpeg)&& ($ extension!= png))
{
$ error 。= ' 未知扩展名!';
$ errors = 1;
}
else
{

$ size = getimagesize($ _ FILES [$ fileElementName] [< span class =code-string>'
tmp_name']);
$ sizekb = filesize($ _ FILES [$ fileElementName] [' tmp_name']);

// 将尺寸与我们定义的最大尺寸进行比较,如果更大则打印错误
if ($ sizekb> MAX_SIZE * 1024)
{
$错误。= ' 您已超出大小限制!';
$ errors = 1;
}
其他 {

// < span class =code-comment>我们将给出一个唯一的名称,例如以unix时间格式表示的时间

$ image_name = time()。' 。'。$ extension;
// 新名称将包含将存储的完整路径(图像文件夹)
$ newname = / images / masters /。$ image_name;
$ copy = copy($ _ FILES [$ fileElementName] [' tmp_name'],$ newname);
// 我们验证图片是否已上传,而是打印错误
if (!$ copy)
{
$ error 。= ' 复制不成功!';
$ errors = 1;
}
其他
{
// < span class =code-comment>新的缩略图图像将放在images / thumbs /文件夹中
$ thumb_name = ' /图像/拇指/拇指_' $ IMAGE_NAME。
// 调用将创建缩略图的函数。该函数将作为参数获取
// 图像名称,缩略图名称和宽度和缩略图所需的高度
$ thumb = make_thumb($ newname,$ thumb_name,40,40);

// 还添加用户pic
$ thumb_name = ' / images / thumbs / thumb _'。$ image_name;
$ thumb = make_thumb($ newname,$ thumb_name,110,110);

}}
}
}

// ---------结束第二篇文章---------------------------------- ----------------------------------

// 将变量返回到javascript
$ filename = $ _FILES [$ fileElementName] [' name'];
$ filesize = round(($ sizekb / 1000),0);
$ fileloc = $ thumb_name ;
// 出于安全原因,我们强行删除所有上传的文件
@取消关联($ _ FILES [$ fileElementName]);
}
$ return_JSON = ;
$ return_JSON 。= {< /跨度>;
$ return_JSON 。= 错误:' $ error ',\ n;
$ return_JSON 。= name:' $ filename ',\ n;
$ return_JSON 。= size:' $ filesize ',\ n;
$ return_JSON 。= loc:' $ fileloc '\ n;
$ return_JSON 。= }< /跨度>;
echo $ return_JSON ;
?>

解决方案

ratio2){


thumb_w =


new_w;


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;
?>

解决方案

ratio2)    {          


thumb_w=


new_w;          


这篇关于如何将PHP代码转换为mvc3或c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆