3

I'm trying to delete a file after it is uploaded via a form and processed:

// 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;
}

I receive the following error:

Error filtering template: Warning: unlink(C:....\MyFile.txt): Resource temporarily unavailable

If I remove the $attachment upload code, then the file is deleted as expected. So I've tried the following, but receive the same Temporarily Unavailable error:

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

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

Am I missing something?

AJK
  • 391
  • 9
  • 27

1 Answers1

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.`