file upload

hello, i have a small problem with my file upload script, for some reason the file size or and the file extensions conditions wont work, and i don`t know why,
everything else works fine, if i wanna upload a file that has the right size it will upload, or if i upload a php file this one will upload too, i dont know why the condition wont kick in
[php]if (isset($_FILES[‘file’])){

				 $target = "../../uploads/"; 
				 $rand = rand(1, 9999);
				 $target = $target . $rand . basename( $_FILES['file']['name']) ; 
				 $file_size = $_FILES['file']['size'];
				 $file_ext = strtolower(end(explode('.', $_FILES['file']['name'])));
				 if ($file_size >= 12000000) {
				 	header("Location: ../files/post?error=2&cid=".$cid);
				 }
				 if ($file_ext == 'php') {
				 	header("Location: ../files/post?error=3&cid=".$cid);
				 }
				move_uploaded_file($_FILES['file']['tmp_name'], $target);
			}[/php]

Here’s a simple code to upload files in database

[php]

<?php include('upload_connection.php'); $upload_file = $_FILES["file"]["tmp_name"]; //file name $des = $_FILES["file"]["name"]; $des1 ='file/'. $des; //folder path where file should go if($_FILES["file"]["error"]>0) { echo "Apologies an error has occured."; echo "Error code:".$_FILES["file"]["error"]; } else { move_uploaded_file($upload_file,$des1); } $sql = "INSERT INTO tablename(id, file_name, file_path) VALUES('','$des','$des1')"; $qry = mysql_query($sql) or die(mysql_error()); echo "Data Inserted"; ?>

[/php]

I have a problem retrieving these uploaded files of any type and extension. Kindly help.

to retrive a file from db i did like this ex: <a href = "<php echo des1; ?>" > Download the file </a>

I think that would create a link.
I would appreciate a help with the code part.

well yes that will create a link to your uploaded file, and if it is any extension besides multymedia or pdf or images it will download it.

this is how i did it:

[php]
$sql = mysql_query(“SELECT * FROM table WHERE id = an ID”);
$get_path = mysql_fetch_assoc($sql);
$path = $get_path[‘des1’];
echo " Download File ";
[/php]

Do you get the right size in the array for $_FILE[name][size] ?
Can you dump the vars ?
or you could try $file_size = file_size($_FILE[name])

i fixed it, it seems that the header needs time to execute so i inserted a die(); function after each header function, problem solved, ty for the help :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service