I have the following script to write a file that i grabbed from online.
$newfname = $data['transferPath'] . '/' . $data['filename'];
$file = fopen ($data['filePath'], "rb");
if(!$file) {
throw new Exception('Unable to open file for reading ' . $file);
}
if($file) {
$newf = fopen ($newfname, "wb");
if(!$newf) {
throw new Exception("Cant open file for writing");
}
if($newf) {
while(!feof($file)) {
fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
}
}
}
if($file) {
fclose($file);
}
if($newf) {
fclose($newf);
}
when i post the data and run this script I keep getting the exception for cant open file for writing because there already is a file but that name in the same directory. Im trying to overwrite the file with the new file any ideas what i can do. iv tried using the options for fopen using w and w+. I need to completely overwrite the file there if exists otherwise create the file.