swooletw / laravel-swoole

High performance HTTP server based on Swoole. Speed up your Laravel or Lumen applications.
MIT License
4.03k stars 388 forks source link

[Question] How to change default base_path so file upload $directory will be default on public folder rather than the root laravel folder? #542

Closed benyaminl closed 1 year ago

benyaminl commented 1 year ago

Make sure you read Issues Guideline and answer these questions before submitting your issue. Thanks! (Any non-English issues will be closed immediately.)

  1. Please provide your PHP and Swoole version. (php -v and php --ri swoole)

The Image used from docker.io/phpswoole/swoole:4.8-php7.4-alpine

/var/www # php -v
PHP 7.4.33 (cli) (built: Nov  3 2022 17:55:42) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
/var/www # php --ri swoole

swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.8.13
Built => Mar  6 2023 17:49:01
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.1.1t  7 Feb 2023
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
zlib => 1.2.12
brotli => E16777225/D16777225
mutex_timedlock => enabled
pthread_barrier => enabled
mysqlnd => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
  1. Please provide your Laravel/Lumen version.

    /var/www # php artisan swoole:http infos
    +-----------------+---------------------------------------+
    | Name            | Value                                 |
    +-----------------+---------------------------------------+
    | PHP Version     | 7.4.33                                |
    | Swoole Version  | 4.8.13                                |
    | Laravel Version | 8.83.27                               |
    | Listen IP       | 0.0.0.0                               |
    | Listen Port     | 8000                                  |
    | Server Status   | Online                                |
    | Reactor Num     | 8                                     |
    | Worker Num      | 8                                     |
    | Task Worker Num | 0                                     |
    | Websocket Mode  | Off                                   |
    | Master PID      | 1                                     |
    | Manager PID     | 12                                    |
    | Log Path        | /var/www/storage/logs/swoole_http.log |
    +-----------------+---------------------------------------+
  2. Which release version of this package are you using? "swooletw/laravel-swoole": "^2.12",

  3. What did you do? If possible, provide a recipe for reproducing the error.

    public function uploadFile(Request $request)
    {
    $request->file("file")->move("uploadImage/", "newname.jpg");
    // ends up in 
    // /var/www/uploadImage/newname.jpg rather than in 
    // /var/www/public/uploadImage/newname.jpg
    }
  4. What did you expect to see?

File uploaded in /var/www/public/uploadImage/newfile.jpg rather in /var/www/uploadImage/newfile.jpg

  1. What did you see instead?

File ends up in /var/www/uploadImage/newfile.jpg

  1. Dockerfile
    
    FROM docker.io/phpswoole/swoole:4.8-php7.4-alpine

RUN adduser ben -u 1001 -D && addgroup tim_it -g 1008 && chown ben:tim_it /var/www WORKDIR /var/www/ COPY . /var/www/ RUN chown ben:tim_it /var/www && chown -R ben:tim_it /var/www/* USER ben RUN composer install --optimize-autoloader --no-dev; exit 0 RUN php artisan optimize:clear RUN php artisan optimize CMD php artisan swoole:http start


I do know there are some option in hot reload, but seems not as I expected to be. 

EDIT: 

I change my `WORKDIR` to the public folder, and do `php artisan swoole:http start` there
```Dockerfile
......
RUN php artisan optimize:clear
RUN php artisan optimize
WORKDIR /var/www/public
CMD php ../artisan swoole:http start

It does change the default folder to /var/www/public. Is it intended to be like this? Thanks

Arkanius commented 1 year ago

Have you tried the public_path() method?

benyaminl commented 1 year ago

@Arkanius same result, I just move the workdir. I don't know why public_path doesn't work