Home > OS >  Inbound Multipart form-data failed to write file to tmp directory on Apache2
Inbound Multipart form-data failed to write file to tmp directory on Apache2

Time:01-18

I am writing a webhook to receive inbound faxes. The inbound POST makes it to the server. The problem is retrieving the attachments to the post. My error log has this message.

 PHP Warning:  copy(/tmp/php4qL9du/pdf-sample.pdf): failed to open stream: No such file or directory in 

The array that is in the $_FILES is this

Array
(
  [attachment] => Array
    (
        [name] => pdf-sample.pdf
        [type] => application/pdf
        [tmp_name] => /tmp/phppw5aIU
        [error] => 0
        [size] => 7945
    )

)

I put the array into variables.

 $inboundFaxDocumentName = $_FILES['attachment']['name'];
 $inboundFaxLocation = $_FILES['attachment']['tmp_name'];
 $inboundFaxFilesize = $_FILES['attachment']['size'];
 $local = $inboundFaxLocation."/".$inboundFaxDocumentName;
 copy($local, "/var/www/html/errors/");

I thought I would go ahead and show what I have for headers on this inbound webhook

header("Access-Control-Allow-Origin: *");
header("Content-Type: multipart/form-data; charset-UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorizations, X-Requested-With");

I have tried to manually go look for the file. I have not been able to find any file. I am not sure what else I can do to troubleshoot this situation. Any suggestions for troubleshooting would be greatly appreciated.

CodePudding user response:

Try just

$local = $inboundFaxLocation;

$_FILES['attachment']['tmp_name'] should already contain a full path to the temporary file, there's no need to add the original name as well.

P.S. Normally in PHP people use move_uploaded_file() specifically for the purpose of transferring an uploaded file from its temporary uploaded location to a more permanent one - there's no point in copying really, because the temp file will be removed anyway after a period of time when the script ends.

  •  Tags:  
  • Related