ファイルを webroot/attach/ にアップロードするこの機能がありました:
public function upload(){
if ($this->request->is('post')) {
if($_FILES["file"]["name"]){
$allowedExts = array("torrent");
$extension = end(explode(".", $_FILES["file"]["name"]));
if (($_FILES["file"]["size"] < 20000)&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
$this->Session->setFlash(__("Upload: " . $_FILES["file"]["name"] . "<br />" .
"Type: " . $_FILES["file"]["type"] . "<br />" .
"Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"
));
if (file_exists("../webroot/attach/torrents/" ."3alany_com_". $_FILES["file"]["name"]))
{
$this->redirect(array('action' => 'index'));
$this->Session->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->Session->read('Auth.User.id');
mysql_set_charset('utf8');
$this->Attachment->query("INSERT INTO attachments (
filename , type , size , user_id
) VALUES (
'{$filename}' , 'torrent', '{$filesize}' , '$user_id'
);");
$this->redirect(array('action' => 'index'));
$this->Session->setFlash(__(" موجود قبل كده يا بوب "));
}
}
}else
{
$this->redirect(array('action' => 'index'));
$this->Session->setFlash(__("أمتداد الفايل مش مقبول"));
}
}
#############IMAGE
if ($_FILES["image"]["name"])
{
if (file_exists("../webroot/attach/images/" ."3alany_com_". $_FILES["image"]["name"]))
{
$this->Session->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->redirect(array('action' => 'index'));
$this->Session->setFlash(__("أمتداد الفايل مش مقبول"));
}
$size = filesize($_FILES['image']['tmp_name']);
if ($size > 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 < 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->Session->read('Auth.User.id');
$this->Attachment->query("INSERT INTO attachments (
filename , type , size , user_id
) VALUES (
'{$filename}' , 'image', '{$filesize}' , '$user_id'
);");
$this->redirect(array('action' => 'index'));
$this->Session->setFlash(__(" موجود قبل كده يا بوب "));
}
}
}
}
しかし、私の問題は、このファイルをlikeで取得する方法です。次のような多くの方法を試しました:
Html->url('/attach/torrents/' . $p['Attachment']['filename'], true); ?>
しかし、それは機能しませんでした。「エラー: AttachController が見つかりませんでした。」
どうすればこのことを処理できますか、ありがとう:) !
追伸:私はケーキを持っています 2