0

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
	}
?>

Edited by JerieLsky: forgot to include the code

Attachments
temperory file name: C:\wamp\tmp\php58.tmp
file name: Misa Campo073.jpg
file size: 126045
file type: image/jpeg
data UmVzb3VyY2UgaWQgIzM=strip Resource id #3
Warning: move_uploaded_file(/www/parctice/test/htdocs/Misa Campo073.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\wamp\www\practice\test\test.php on line 18

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\wamp\tmp\php58.tmp' to '/www/parctice/test/htdocs/Misa Campo073.jpg' in C:\wamp\www\practice\test\test.php on line 18
something went wrong.
4
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by Javvy
0

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');

Edited by paulrajj: n/a

0

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

0

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

Edited by pzuurveen: n/a

0

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.

Edited by JerieLsky: n/a

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.