help

i was just given an assignment and im completely lost:

All code must be able to run under an Apache webserver using PHP4 and MySQL if needed.

  1. Design a class to access files on a local filesystem. This must include opening a file, making changes, and saving the file. It is important to include the ability to binary read and write so any type of file can be edited. The class should be easy to use and include appropriate error checking.

  2. Using the class created in question 1 write a function that will accept the url of a valid image(jpg, gif, png) and download the file to the local machine in a folder called “external_images”. The filename saved should be the return value of the function. The function should be easy to use and include appropriate error checking

[php]<?php

$Script = new Script();

class Script
{

	function fileOpen($filepath){
		if(!file_exists($filepath)){
			echo 'File doesnt exist';
			return false;
		}else{
			if(!$file = fopen('filepath','w+b')){
				echo 'Unable to open file';
			}else{
				echo file_get_contents($filepath);					
			}
		}
		fclose($file);
	}

}

$filepath = ‘D:\xampp**\a.txt’;
$Script->fileOpen($filepath);
?>[/php]

Does that make sense?

That code won’t work. You’re instantiating the class before you’ve declared it. Also, you should always omit the closing PHP tag (?>). If you were to accidentally add whitespace after it, you may get header errors.

Works perfectly fine for me and is a helpful start for his study.
Also your making comments on old posts that haven’t had replies in a while

Yes, lothop, you are correct and he is wrong.

“instantiating the class” has nothing to do with where the class is located…

His way does look a little better, but, for a beginner, functionality is much better than style.

Sponsor our Newsletter | Privacy Policy | Terms of Service