简体   繁体   中英

FWRITE() Saving file to a specific location

This code below is using the FWRITE function. however i wish to save the file to a specific location but always get 'cant open file' as expected. i have setup the directory listed in mypath but it still wont write to that location.

   $mypath = "http://www.mysite.com/test/data/";
    $myFile = $mypath."data.txt";
    $fh = fopen($myFile, 'w') or die("can't open file");
    $stringData = "Some text";
    fwrite($fh, $stringData);
    fclose($fh);

The HTTP wrapper does not support writing. If mysite.com is the same server you're running on, and that's a physical directory, you would use a regular file path (no HTTP). What filename that URL corresponds to depends entirely on how your server is set up.

If it's a different machine, you need to use curl or another solution to do a PUT or POST.

Try using a logical path to save the file such as:

/home/mysitefolder/public_html/test/data/

also check to make sure that PHP is running as Apache and has permissions to write to that folder.

Your path is wrong; you can't use http:// as a path, you need something like /var/www/test/data as $mypath .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM