Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write to tmp folder

EDIT 1

This question involves the user of the MANGOPAY API. My problem is that I cannot get the API to write to the tmp folder.

I have succeeded in getting the API to write to http://fakedomain.com/apifolder/blank.txt and getting the appropriate output.

I then ran the script http://fake.com/apifolder/demos/iswrite.php on http://fakedomain.com/apifolder/blank.txt to have minimal working code I could test on the tmp folder. Here is the code in the script:

<?php

$filename = 'blank.txt';


echo "<br>";


file_exists($filename);

echo "<br>";



if (file_exists($filename)) {
    echo "The file $filename exists";
} else {
    echo "The file $filename does not exist";
}

echo "<br>";

if (is_writable($filename)) {
    echo 'The file is writable';
} else {
    echo 'The file is not writable';
}

?>

It gives me the output

The file blank.txt exists The file is writable

so all good there. I created the following file with the following permissions using Filezilla:

enter image description here

In the script http://fake.com/apifolder/demos/iswrite.php I have changed the filename variable to $filename = 'http://fake.com/tmp/creative/blank.txt';. It gives me the following output:

The file http://fake.com/tmp/creative/blank.txt does not exist The file is not writable

Also, allow_url_fopen is on.

I don't fully understand URL structures, so maybe the problem lies there? The tmp folder I am trying to access is on the same level as my public_html folder. Maybe I am writing my URLs wrong?

enter image description here

Put in another way, does the tmp folder have to be outside the public_html folder? Would there be any purpose to this? Or can I have create my own tmp folder within public_html where it is already working?


ORIGINAL QUESTION

The original question was poorly written. Please see EDIT 1

I am playing with the sandbox of an API (MangoPay). I have included my ClientId and ClientPassword which seems to work.

The API also says...

You also need to set a folder path in $api->Config->TemporaryFolder that SDK needs to store temporary files. This path should be outside your www folder. It could be /tmp/ or /var/tmp/ or any other location that PHP can write to.

I have created one at:

ftp://fakedomain@fakedomain/tmp/fakefoldername

I am running the php script from my desktop using Terminal. The output it is giving me is

Cannot create or write to file ftp://fakedomain@fakedomain/tmp/fakefoldername

even though I have set permissions to 777.

Any idea of why I am getting this error?

like image 772
Eric Brotto Avatar asked Nov 06 '15 13:11

Eric Brotto


2 Answers

I am guessing the library in question is this one, and the error you are getting is this exception:

 if (!is_writable($this->GetPathToTemporaryFolder()))
            throw new \MangoPay\Libraries\Exception('Cannot create or write to file ' . $this->GetPathToTemporaryFolder());

So basically we seem to be debugging a call to is_writable().

  1. make sure allow_url_fopen is on
  2. if applicable, make sure the URL includes the FTP password
  3. make sure the folder exists and the FTP account has write permissions (777 should suffice...)
like image 184
RandomSeed Avatar answered Oct 21 '22 06:10

RandomSeed


Generally speaking a temp dir is supposed to be located on the same machine as your code. Using FTP is less than ideal. Are you not able to use a local directory?

You'll notice in the MangoPay documentation it shows a local dir:

https://github.com/Mangopay/mangopay2-php-sdk

$api->Config->TemporaryFolder = '/some/path/';

You should probably stick to that, instead of using a remote server via FTP.

like image 28
Ian Avatar answered Oct 21 '22 07:10

Ian