Kritim Yantra
Apr 10, 2025
When working with file uploads in PHP applications using libraries like VueFinder-PHP, you might encounter the frustrating error:fopen(/var/www/html/public): Failed to open stream: Is a directory
.
This comprehensive guide explains why this error occurs and provides multiple solutions, including Docker-specific configurations.
This error typically occurs when:
Locate your php.ini file (often in /etc/php/8.x/fpm/php.ini
or /etc/php/8.x/cli/php.ini
) and modify these values:
memory_limit = 512M
upload_max_filesize = 512M
post_max_size = 512M
max_execution_time = 300
max_input_time = 300
Then restart your PHP service:
sudo service php8.2-fpm restart
sudo chown -R www-data:www-data /var/www/html/public
sudo chmod -R 755 /var/www/html/public
For Docker users, here's a complete Dockerfile solution that addresses all common issues:
# Use official PHP image
FROM php:8.2-fpm
# Install system dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
supervisor \
git \
curl \
libzip-dev \
libbz2-dev \
libjpeg-dev \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip \
libfreetype6-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Custom PHP settings for file uploads
RUN printf "[custom-php]\n\
memory_limit=512M\n\
upload_max_filesize=512M\n\
post_max_size=512M\n\
max_execution_time=300\n\
max_input_time=300\n\
max_file_uploads=100\n" \
> /usr/local/etc/php/conf.d/99-custom-php.ini
# Install PHP extensions
RUN docker-php-ext-install gd pdo iconv bcmath mbstring pdo_mysql zip exif pcntl
# Set working directory
WORKDIR /var/www/html
# Copy application source
COPY ./ /var/www/html
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
# Install Node.js
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
apt-get install -y nodejs
# Set permissions (critical for VueFinder)
RUN chown -R www-data:www-data /var/www/html && \
chmod -R 755 /var/www/html/storage && \
chmod -R 755 /var/www/html/public
# Copy Supervisor configuration
COPY ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# Copy entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
# Convert Windows line endings to Unix-style
RUN apt-get update && apt-get install -y dos2unix && \
dos2unix /usr/local/bin/docker-entrypoint.sh
# Set entrypoint script permissions
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Expose port 8000 for Laravel app
EXPOSE 8000
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
If you're using VueFinder-PHP specifically, add these configurations:
'disks' => [
'vuefinder' => [
'driver' => 'local',
'root' => public_path('uploads'),
'url' => env('APP_URL').'/uploads',
'visibility' => 'public',
'throw' => false,
],
],
<?php
namespace App\Http\Middleware;
use Closure;
class IncreaseUploadLimits
{
public function handle($request, Closure $next)
{
ini_set('upload_max_filesize', '512M');
ini_set('post_max_size', '512M');
ini_set('memory_limit', '512M');
ini_set('max_execution_time', '300');
return $next($request);
}
}
Then register it in your bootstrap/app.php:
<?php
use Illuminate\Foundation\Application;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php'
)
->withMiddleware(function ($middleware) {
$middleware->alias([
'upload-limit' => \App\Http\Middleware\IncreaseUploadLimits::class
]);
})
->create();
After applying these changes:
<?php
phpinfo();
Look for:
ls -la /var/www/html/public
Check PHP error logs:
tail -f /var/log/php8.2-fpm.log
Verify Nginx/Apache configuration:
Ensure your web server has proper client_max_body_size settings
Test with a simple upload script:
<?php
if ($_FILES) {
move_uploaded_file($_FILES['file']['tmp_name'], 'test.upload');
echo "Upload successful!";
}
?>
<form method="post" enctype="multipart/form-data">
<input type="file" name="file">
<button>Upload</button>
</form>
The "fopen(): Failed to open stream: Is a directory" error in VueFinder-PHP typically stems from either permission issues or PHP configuration limits. By implementing the solutions above - whether you're using a standard PHP installation or Docker - you should be able to resolve the file upload issues and have VueFinder-PHP working smoothly.
Remember to:
For Docker users, the provided Dockerfile includes all necessary configurations to prevent these issues from occurring in your containerized environment.
No comments yet. Be the first to comment!
Please log in to post a comment:
Sign in with Google