title: upload function in cakephp, how to get the url
body: <p>i have had this function to upload files to webroot/attach/ :</p>
  
  <pre><code>   public function upload(){
  
      if ($this-&gt;request-&gt;is('post')) {
          if($_FILES["file"]["name"]){
      $allowedExts = array("torrent");
      $extension = end(explode(".", $_FILES["file"]["name"]));
      if (($_FILES["file"]["size"] &lt; 20000)&amp;&amp; in_array($extension, $allowedExts))
      {
      if ($_FILES["file"]["error"] &gt; 0)
      {
      echo "Return Code: " . $_FILES["file"]["error"] . "&lt;br /&gt;";
      }
      else
      {
      $this-&gt;Session-&gt;setFlash(__("Upload: " . $_FILES["file"]["name"] . "&lt;br /&gt;" . 
       "Type: " . $_FILES["file"]["type"] . "&lt;br /&gt;" . 
       "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb&lt;br /&gt;"
      ));
      if (file_exists("../webroot/attach/torrents/" ."3alany_com_". $_FILES["file"]["name"]))
        {
      $this-&gt;redirect(array('action' =&gt; 'index'));
      $this-&gt;Session-&gt;setFlash(__($_FILES["file"]["name"] . " موجود قبل كده يا بوب "));   
        }
      else
        {
        move_uploaded_file($_FILES["file"]["tmp_name"],
        "../webroot/attach/torrents/"."3alany_com_". $_FILES["file"]["name"]);
  
          $filename = "3alany_com_". $_FILES["file"]["name"];
          $filesize = $_FILES["file"]["size"];
          $user_id = $this-&gt;Session-&gt;read('Auth.User.id');
          mysql_set_charset('utf8');
  
      $this-&gt;Attachment-&gt;query("INSERT INTO attachments (
                  filename ,  type , size , user_id
                  ) VALUES (
                  '{$filename}' , 'torrent', '{$filesize}' , '$user_id' 
                  );");
  
      $this-&gt;redirect(array('action' =&gt; 'index'));
      $this-&gt;Session-&gt;setFlash(__(" موجود قبل كده يا بوب ")); 
        }
      }
      }else
        {
      $this-&gt;redirect(array('action' =&gt; 'index'));
      $this-&gt;Session-&gt;setFlash(__("أمتداد الفايل مش مقبول")); 
        }
      }
  
  
  #############IMAGE
  
  if ($_FILES["image"]["name"])
  {
  if (file_exists("../webroot/attach/images/" ."3alany_com_". $_FILES["image"]["name"]))
  {
      $this-&gt;Session-&gt;setFlash(__($_FILES["image"]["name"] . " موجود قبل كده يا بوب "));  
  }
  else
  {
  
  $uploadedfile = $_FILES['image']['tmp_name'];
  $file_name = stripslashes($_FILES['image']['name']);
  $boss = explode(".", strtolower($file_name));
  $extension = strtolower(end($boss)); 
  $array = array('jpg', 'jpeg', 'png', 'gif'); 
  if (!in_array($extension, $array))
  {
      $this-&gt;redirect(array('action' =&gt; 'index'));
      $this-&gt;Session-&gt;setFlash(__("أمتداد الفايل مش مقبول")); 
  }
  $size = filesize($_FILES['image']['tmp_name']);
  if ($size &gt; 10000000)
  {
  echo "الصوره المضاعه كبيره";
  exit;
  }
  if ($extension == "jpg" || $extension == "jpeg")
  {
  $src = imagecreatefromjpeg($uploadedfile);
  } else
  if ($extension == "png")
  {
  $src = imagecreatefrompng($uploadedfile);
  } else
  {
  $src = imagecreatefromgif($uploadedfile);
  }
  list($width, $height) = getimagesize($uploadedfile); 
  if ($width &lt; 685)
  {
  $newwidth = $width;
  } else
  {
  $newwidth = 500;
  };
  $newheight = ($height / $width) * $newwidth;
  $tmp = imagecreatetruecolor($newwidth, $newheight);
  imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  
  $filename = "../webroot/attach/images/". "3alany_com_" . $file_name;
  imagejpeg($tmp, $filename, 100);
  imagedestroy($src);
  imagedestroy($tmp);
  
          mysql_set_charset('utf8');
      $filename = "3alany_com_". $_FILES["image"]["name"];
      $filesize = $_FILES["image"]["size"];
      $user_id = $this-&gt;Session-&gt;read('Auth.User.id');
      $this-&gt;Attachment-&gt;query("INSERT INTO attachments (
                  filename ,  type , size , user_id
                  ) VALUES (
                  '{$filename}' , 'image', '{$filesize}' , '$user_id' 
                  );");
  
  
  $this-&gt;redirect(array('action' =&gt; 'index'));
  $this-&gt;Session-&gt;setFlash(__(" موجود قبل كده يا بوب ")); 
  
        }
  
  }
  
  
  
  
  }
  }
  </code></pre>
  
  <p>but my problem is how to get this files with a like, i have tried many ways like :</p>
  
  <blockquote>
    Html->url('/attach/torrents/' .
    $p['Attachment']['filename'], true); ?>
  </blockquote>
  
  <p>but it didn't work, it's give me " Error: AttachController could not be found."</p>
  
  <p>so how can i handle this thing, thanks :) !</p>
  
  <p>ps:i have cake 2</p>