简体   繁体   English

在 cakephp 的 webroot/img 文件夹外上传图片

[英]upload image outside cakephp's webroot/img folder

I am building a web application using CakePHP.我正在使用 CakePHP 构建一个 web 应用程序。 I am using meioupload to upload the images.我正在使用meioupload上传图片。 These images are successfully uploaded.这些图像已成功上传。 I would like to separate the admin-app and public-app into, of course, two separate CakePHP applications.当然,我想将 admin-app 和 public-app 分成两个单独的 CakePHP 应用程序。 The problem is that I can't share the images that were uploaded into the public-app's webroot with the admin-app's webroot and vice versa.问题是我无法与管理应用程序的 webroot 共享上传到公共应用程序的 webroot 的图像,反之亦然。 I am thinking about uploading these images into another folder outside those two apps.我正在考虑将这些图像上传到这两个应用程序之外的另一个文件夹中。 Am I on the right track?我在正确的轨道上吗? If I am, how can I do this?如果我是,我该怎么做?

Thanks.谢谢。

One solution is to modify your script to upload your images to a "shared" directory which can be view by both applications.一种解决方案是修改脚本以将图像上传到两个应用程序都可以查看的“共享”目录。 Or, if you're on a Linux-like OS, you could make this shared directory under the document root and have a symbolic link created between the directories that each application will call.或者,如果您使用的是类似 Linux 的操作系统,您可以在文档根目录下创建这个共享目录,并在每个应用程序将调用的目录之间创建一个符号链接。

So APP1 and APP2 could both upload to /var/sharedStuff .所以 APP1 和 APP2 都可以上传到/var/sharedStuff APP1 is located at /var/www/app1 and APP2 is located at /var/www/app2 Both of these apps could have a directory that is symlinked to the sharedStuff directory. APP1 位于/var/www/app1和 APP2 位于/var/www/app2这两个应用程序都可以有一个与 sharedStuff 目录符号链接的目录。 So /var/www/app1/app/webroot/img/shared and /var/www/app2/app/webroot/img/shared would both internally point to /var/sharedStuff .所以/var/www/app1/app/webroot/img/shared/var/www/app2/app/webroot/img/shared都将在内部指向/var/sharedStuff You could then reference these images from your application just as if they were placed in that img/shared directory.然后,您可以从您的应用程序中引用这些图像,就像它们被放置在img/shared目录中一样。 Again, You'd need to modify your upload script to make sure it uploads files to this shared directory (or symlink) and not in an exclusive one.同样,您需要修改您的上传脚本以确保它将文件上传到此共享目录(或符号链接)而不是独占目录。

Just to let you know, CakePHP has built in functionality for creating your own admin interface.只是让您知道,CakePHP 具有用于创建您自己的管理界面的内置功能。 There are many tutorials out there.那里有很多教程。 Just a Google search away.只需谷歌搜索即可。 Separating them into two applications seems less than ideal.将它们分成两个应用程序似乎不太理想。

using meioupload, it turn out that i can use relative path, so i do it like this:使用 meioupload,事实证明我可以使用相对路径,所以我这样做:

public $actsAs = array(
    'MeioUpload' => array(
        'filename' => array(
            'dir' => '../../../path/to/outside/webroot',
            'create_directory' => true,
        )
    )
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM