Alice Wei wrote:
> Hi, 
> 
>    I have a simple code as shown in the following:
> 
> <?php
> 
> //original file
> $file = "http://remote_server/copy/play.txt";;
> $file2 = "http://remote_server/copy/test.jpg";;
> $file3 = "http://remote_server/copy/sample.pdf";;
> 
> //directory to copy to (must be CHMOD to 777)
> $copydir = ".";
> 
> $data = file_get_contents($file);
> $file2 = fopen($copydir . "/play.txt", "w+");
> fputs($file2, $data);
> fclose($file2);
> 
> $data2 = file_get_contents($file2);
> $file3 = fopen($copydir . "/test.jpg", "w+");
> fputs($file3, $data2);
> fclose($file3);
> 
> $data3 = file_get_contents($file3);
> $file4 = fopen($copydir . "/sample.pdf", "w+");
> fputs($file4, $data3);
> fclose($file4);
> 
> $data5= file_get_contents("play.txt");
> echo $data5 . "<br>";
> 
> $data6= file_get_contents("test.jpg");
> echo $data6 . "<br>";
> 
> $data7= file_get_contents("sample.pdf");
> echo $data7 . "<br>";
> 
> ?> 
> 
> The first  one, $file, has no problems, and I did get the contents copied 
> correctly. However, the second and third one, I get this error: 
> 
> Warning: file_get_contents() expects parameter 1 to be string, resource 
> given in C:\Inetpub\wwwroot\test\hello.php on line 
> 18
> ./test.jpg 
> Warning: file_get_contents() expects parameter 1 to be string, resource 
> given in C:\Inetpub\wwwroot\test\hello.php on line 
> 25
> ./sample.pdf
> 
> I notice that the empty file gets created correctly, but I cannot put in the 
> file contents. If file_get_contents only supports text, could anyone please 
> give me some suggestions on what type of function I should use to put in the 
> file contents so that it is readable?
> 
> Thanks in advance.
> 
> Alice
> _________________________________________________________________
> Use Messenger to talk to your IM friends, even those on Yahoo!
> http://ideas.live.com/programpage.aspx?versionId=7adb59de-a857-45ba-81cc-685ee3e858fe

Well, that's because you are probably thinking that $file2 =
"http://remote_server/copy/test.jpg";; because you assigned it at the
beginning of your code.  However, later in your code you do $file2 =
fopen($copydir . "/play.txt", "w+"); which assigns a file pointer
resource to $file2, which overwrites what you previously assigned.  Try
not using the same variable name for4 multiple things ;-)

Same for $file3.

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to