Page 1 of 1

[SOLVED] upload code doesn't upload files

Posted: Fri May 06, 2005 2:47 pm
by ddragas
Why this code doesn't upload files?
Please take a look

file form.html

Code: Select all

<body>
<form enctype="multipart/form-data" action="uploadaj.php" method="POST">
Upload file: <input name="file_name" type="file">
<input type="submit" value="Uploadaj">
</form>
</body>

file uploadaj.php

Code: Select all

<?php


$temp_filename = $_FILES['file_name']['tmp_name'];
$ime_filea_na_disku = $_FILES['file_name']['name'];
$filename = $_FILES['file_name']['name']; // get file name
$size_u_bajtovima = $_FILES['file_name']['size'];
$extension = strtolower(strrchr($filename,".")); // get everything after the last . and include the . Also lowercases the string for easier file checking
$extensions = array('.gif','.jpg','.jpeg','.png');  // Allowed File Types 
if (!in_array($extension, $extensions))
	 	{ 
	 		echo "File type not allowed." . "<br>";
			echo $extension; 
		} 
			else
				{
					$zeljena_max_velicina = 1024*500; // 500 KB
						if($size_u_bajtovima > $zeljena_max_velicina + 1) 
							{
  								die('Poslali ste prevelik file');
							}
								else
									{

										$Photo_Dir = "uplodani_fajlovi/";//"../uploadedfiles/apartmani/"; 
										$userID = "674893279/";//$Sifra_apartmana ."/"; 

	   										if (!is_dir($Photo_Dir . $userID)) 
							               { 
							                    mkdir ($Photo_Dir . $userID, 0777); 
							                    chmod ($Photo_Dir . $userID, 0777); 
							               }
										   		

												srand((double)microtime()*1000000);

												$uploadfile = $Photo_Dir . $userID . rand(5000,1000000) . $extension;
												
												if(copy($_FILES['userfile']['tmp_name'], $uploadfile)){
								
												echo $_FILES['userfile']['tmp_name'] . " Fajl je uploadan u " . $uploadfile;}

?>

Posted: Fri May 06, 2005 3:45 pm
by John Cartwright
What is happening as of now?
Any output? Errors?

Have you checked print_r($_FILES) to see if the file is correctly being submitted?

Posted: Fri May 06, 2005 9:21 pm
by hongco
line 39 if(copy($_FILES['userfile']['tmp_name'], $uploadfile))

should've been:

Code: Select all

if(copy($_FILES['file_name']['tmp_name'], $uploadfile))
file_name instead of userfile.

Posted: Fri May 06, 2005 10:59 pm
by CheetahShrk
Are you sure the code just isn't cut off because the code in the code box is missing some closing...

Posted: Sat May 07, 2005 12:42 am
by ddragas
thank you folks. It is working now.