James Bedret James Bedret - 1 year ago 209
Apache Configuration Question

Save file with file_put_contents in folder


This working ok - save file in current folder, but if i try:


then i have error:

failed to open stream: No such file or directory in


why? How can i save this in subfolder?

Answer Source

Always use full paths and make sure the directory is writable. You can also use copy directly with URL

$url = 'http://static.adzerk.net/Advertisers/12f0cc69cd9742faa9c8ee0f7b0d210e.jpg';
$dir = __DIR__ . "/subfolder"; // Full Path
$name = 'image.jpg';

is_dir($dir) || @mkdir($dir) || die("Can't Create folder");
copy($url, $dir . DIRECTORY_SEPARATOR . $name);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download