Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tearing images

Status
Not open for further replies.

GIGN

Programmer
Oct 6, 2000
1,082
NZ
I need a way of grabbing binary files from another server, and saving them someplace else - I seem to be able to read them O.K. with readfile() etc, but can't find anything to save it as an image.
[bb]
 
Read the PHP documentation more about how PHP handles files, both remote and local: and
Here is an example from the user comments at the second link:

Code:
A sample, how to save a simple jpeg image! 
<? 
$fc = fopen(&quot;myimage.jpg&quot;, &quot;wb&quot;);
// this is the LOCAL file location you will save to
$file = fopen (&quot;[URL unfurl="true"]http://www.pic.com/image2.jpg&quot;,[/URL] &quot;rb&quot;); 
// this is the remote file location

if (!$file) { 
echo &quot;Unable to open remote file.\n&quot;; 
exit; 
} 
else 
{ 
while (!feof ($file)) { 
$line = fread ($file, 1028); 
fwrite($fc,$line); 
} 

} 
fclose($fc); 
fclose($file); 
echo &quot;ok&quot;; 
?>
 
Cheers, I have scoured the manual to no avail, so hopefully something there will help out!

 
Hmmm, more straight forward than I thought, however I cannot seem to write to files on a server.

If I copy them down straight to a file path C:\\... then it copies them, but the minute I try to use a server path, even 127.0.0.1... then the copy fails.

I do not get any error - and the while loop still executes, but the files does not update.

ideas?

[bb]
 
Well, of course you can't simply write or copy files to a path using an IP address. (How secure would our networks be???) File writing and copying assumes local hard drive paths, or mapped network paths (Windows file share, NFS, etc...), not just generic network paths, and what protocol are you trying to use when you write to the IP address?

Since it seems you are using Windows, I'll assume you are trying to save to another windows system: it's the same as if you as a local user on the server trying to save a file somewhere. Either you use a local path, such as C:\\..., or you map a network location to a hard drive letter, such as F:\\, then you treat it as a local address. I suppose you could try to direct PHP to navigate a windows network share, with paths such as &quot;\\servername\directory&quot;, but I doubt it is that simple.

Also, there is the question of user permissions. If you are using NT, I'm not totally sure how to approach this. I suppose you could just share your remote server directory with &quot;Everybody->Full Control&quot;, but that is pretty insecure. If you are using IIS, then I believe the default user for the server process is IUSR_{servername}, but I'm not totally sure about that. Anyway, standard Windows network share permission methods should apply to this situation.

Or... if you installed PHP with FTP functionality, then you could use the FTP functions to save a files to any remote server that is running FTP server. Otherwise, you should map your network drive, and let PHP treat the path as a local one. -------------------

Current reading --
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top