Hi, im trying to upload a file(.pdf, .jpg, .bmp, etc.. ) but I'm getting this error message.. check the file I've attached, it contains the output on the page but with errors..

<?php
	define("REPOSITORY", "/www/parctice/test/htdocs");
	if(isset($_POST['submit'])){
		if(is_uploaded_file($_FILES['fileupload']['tmp_name'])){
			echo "temperory file name: " . $_FILES['fileupload']['tmp_name'] . "<br />";
			echo "file name: " . $_FILES['fileupload']['name'] . "<br />";
			echo "file size: " . $_FILES['fileupload']['size'] . "<br />";
			echo "file type: " . $_FILES['fileupload']['type'] . "<br />";
			$fileName=$_FILES['fileupload']['name'];
			$tmpFileName=$_FILES['fileupload']['tmp_name'];			
			//check file type
			//test base64_encode _decode
				$data=base64_encode(addslashes(fopen($tmpFileName, "r", filesize($tmpFileName))));
				echo "data " . $data;
				print "strip " . stripslashes(base64_decode($data));
			//test
			if($_FILES['fileupload']['type'] == "images/jpeg" || "images/bmp"){
				$result == move_uploaded_file($tmpFileName, REPOSITORY . "/$fileName");
				if($result==1){
					echo "file successfully uploaded.";
				}else{
					echo "something went wrong.";
				}
			}else{
				echo "not a valid file type";
			}
		}else{
			$err_Number = $_FILES['fileupload']['error'];
			switch($err_Number){
				case 1: echo "<b>UPLOAD_ERR_INI_SIZE: Err Num $err_Number </b>- There was an attempt to upload a file whose size exceeds the value specified by the <i>upload_max_filesize</i> directive.";
					break;
				case 2: echo "<b>UPLOAD_ERR_FORM_SIZE: Err Num $err_Number </b>- There was an attempt to upload a file whose size exceeds the value of the <i>max_file_size</i> directive, which can be embedded into the HTML form.";
					break;
				case 3: echo "<b>UPLOAD_ERR_PARTIAL: Err Num $err_Number </b>- A file is not completely  uploaded. ";
					break;
				case 4: echo "<b>UPLOAD_ERR_NO_FILE: Err Num $err_Number </b>- No file specified.";
					break;
			}
		}
	}else{
?>
<html>
<head>
	<title>Test</title>
</head>
<body>
<form action="" method="POST" enctype="multipart/form-data">
	File: <input type="file" name="fileupload" />
	<br /><input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
<?php
	}
?>

Hi,

The problem is in defining the uploading directory (REPOSITORY). Try changing by adding document_root path to the REPOSITORY url.

define("REPOSITORY", $_SERVER['DOCUMENT_ROOT']);

Now the files will upload to the document root path. By concatenating the document root path with your specified directory, the images will upload to that directory (/parctice/test/htdocs).

define("REPOSITORY", $_SERVER['DOCUMENT_ROOT'].'/parctice/test/htdocs');

I 'm always suspicious about filenames with spaces

$fileName=str_replace(" ","_",$fileName);

paulrajj: I'll check if it would work. I'll let you know.
pzuurveen: What?

from your err msg
file name= /www/parctice/test/htdocs/Misa Campo073.jpg linux will read this as call to /www/parctice/test/htdocs/Misa passing a parameter Campo073.jpg

Hi,

The problem is in defining the uploading directory (REPOSITORY). Try changing by adding document_root path to the REPOSITORY url.

define("REPOSITORY", $_SERVER['DOCUMENT_ROOT']);

Now the files will upload to the document root path. By concatenating the document root path with your specified directory, the images will upload to that directory (/parctice/test/htdocs).

define("REPOSITORY", $_SERVER['DOCUMENT_ROOT'].'/parctice/test/htdocs');

I tried inserting the $_SERVER; but still i'm getting the same error like before. Any other more suggestions on this problem? Please help.

Did you spell practice wrongly? Or does the folder parctice exist?

Did you spell practice wrongly? Or does the folder parctice exist?

Oh wow! My bad! A simple typo error. That made it work. Thanks. I'll get back if there are other errors. :D

No problem. Cheers :)