473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Copying file gives 0kb file

KeredDrahcir
426 256MB
I'm trying to copy a file from a remote location and the file copies across but has a size of 0kb. Can anyone suggest why this is happening?
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.   function copyFile($url,$dirname)
  3.   {
  4.     @$file = fopen ($url, "rb");
  5.     if (!$file)
  6.     {
  7.       echo"<font color=red>Failed to copy $url!</font><br/>";
  8.       return false;
  9.     }
  10.     else
  11.     {
  12.       $filename = basename($url);
  13.       $fc = fopen($dirname."$filename", "wb");
  14.       while (!feof ($file))
  15.       {
  16.         $line = fread ($file, 1028);
  17.         fwrite($fc,$line);
  18.       }
  19.       fclose($fc);
  20.       echo "<font color=blue>File $url saved to PC!</font><br/>";
  21.       return true;
  22.     }
  23.   }
  24. ?>
  25.  
  26. <?php
  27.   $filedir=$_SERVER['DOCUMENT_ROOT']."/include/";
  28.   copyFile("http://remote location.co.uk/include/file.php",$filedir);
  29. ?>
Jul 19 '10 #1
5 2942
dlite922
1,584 Expert 1GB
Have you done any debugging?

out put $line in your while loop, see if you can at least determine that is content to be written.

I don't see you checking the output of fwrite to see if it's not false.

Dan
Jul 19 '10 #2
KeredDrahcir
426 256MB
Good point. Thanks I'll give that a try.
Jul 20 '10 #3
KeredDrahcir
426 256MB
Could this be anything to do with the file I'm trying to copy being a php file?
Jul 21 '10 #4
KeredDrahcir
426 256MB
The file might be one a remote site but it's on the same server so I've managed to access it through the server just by going up two layers from the public_html layer to the home layer.

Expand|Select|Wrap|Line Numbers
  1. require($_SERVER['DOCUMENT_ROOT'].'/../../domain_name/public_html/folder/file.php');
Jul 22 '10 #5
Oralloy
988 Expert 512MB
I'm not a PHP guy, but it seems to me that you're reading from a "URL".

Also, you note in your request that the file is "remote".

If that's the case, I would think you'd need to use a HTTP client object to access the remote file. Isn't "fopen" only for the computer's local file system, like in "C"?
Jul 23 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: REM | last post by:
I have some problems. It's dilemma between BLOB, BFILE and takes care of file on file system. What it's advantage?? I import some PDF document in BLOB filed in my database. It's about 1000...
1
by: Daniel Cardoso | last post by:
I don't know what else to try - In my asp.net app, when the file name has Windows-1252 characters (like ã and ç), these characters appear, each one, as two strange characters in the file name label...
19
by: **Developer** | last post by:
When I get the image from the file the file remains locked so the Delete fails with a "used by another process" So I tried using a clone and disposing the obtained image. But that didn't fix...
0
by: suryanector | last post by:
anybody knows source code for programs using Index file, inverted file operations, usage of B and B++ trees in C++ language plz send them.
10
by: vunet.us | last post by:
What is the workaround of passign a parameter to any included asp file: <!-- #Include File="file.asp" --> This obviously does not work: <!-- #Include File="file.asp?id=123" --> Thank you
1
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post by:
Hi, Anyone know of a folder equivalent to File.Exist(file) ? regards Jesper.
2
by: charlesbritto | last post by:
A C++ program for counting individual string in a text file using file handling functions., for ex: if the text file contains, am a boy,am studying +2,am from chennai Now the result shoud...
6
by: Claire | last post by:
I've noticed after copying a text file line by line and comparing, that the original had several bytes of data at the beginning denoting its encoding. How do I use that in my copy? My original...
8
by: raylopez99 | last post by:
I have the latest version of Visual Studio 2008 Professional, which allows you to create resource files (this is the .resx file, no?), unlike the Express version, which does not. I am trying to...
3
by: ndoe | last post by:
how to make a paragraph from file to file like this e.g data.txt i want eat some pizza with
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.