PHP:取消链接资源暂时不可用

问题描述 投票:0回答:1

我试图在通过表单上传并处理文件后删除该文件:

// FORM SUBMIT
if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $uploadfile = getcwd() . '/pub/media/dealers/' . basename($_FILES['proof']['name']);

    move_uploaded_file($_FILES['proof']['tmp_name'], $uploadfile);

    // Upload attachment to Zendesk
    $attachment = $client->attachments()->upload([
      'file' => $uploadfile
    ]);

    unlink($uploadfile);
    exit;
}

我收到以下错误:

过滤模板错误:警告: 取消链接(C:....\MyFile.txt):资源 暂时无法使用

如果我删除

$attachment
上传代码,则文件将按预期删除。所以我尝试了以下方法,但收到相同的“暂时不可用”错误:

$attachment = $client->attachments()->upload([
    'file' => $uploadfile
  ]);

unset($attachment);
unlink($uploadfile);

我错过了什么吗?

php delete-file unlink
1个回答
0
投票
    if (file_exists(public_path($category->image))) 
                {
                    unlink(public_path($category->image));
                }

   'It gives the same error in the above code, but if it fixes it as follows, we do not get the following error:'

if(!empty($category->image)){
        if (file_exists(public_path($category->image))) {
            unlink(public_path($category->image));
        }
        }

`The file we are going to update should not be empty.`
© www.soinside.com 2019 - 2024. All rights reserved.