tags:

views:

23

answers:

3

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);
+2  A: 

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.

Matthew Flaschen
A: 

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

Oliver
A: 

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.

Wright-Geek