【问题标题】:How to check if a file exists in a url in laravel如何检查文件是否存在于laravel的url中
【发布时间】:2020-06-25 06:18:34
【问题描述】:
@if (file_exists(env('BASE_URL_MASTER').$p->main_image))

<img class="primary-img" src="{{env('BASE_URL_MASTER').$p->main_image}}" alt="single-product" height="200px" width="400px">

@else
<img class="primary-img" src="{{asset($p->main_image?$p->main_image:'')}}" alt="single-product" height="200px" width="400px">
endif

如果图像可用,我想检查给定的 URL 是否有图像,那么@if 条件应该有效。但它不起作用

【问题讨论】:

标签: laravel laravel-5 laravel-4


【解决方案1】:

改用file_get_content()。 例子: $file = file_get_content('url_to_file or path_to_file'); if (strlen($file) > 0) 'file exist...'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-02
    • 2015-03-07
    • 2011-12-02
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 2010-09-16
    相关资源
    最近更新 更多