i am missing something

<?php
$target = "images/dars/";

$target = $target . basename( $_FILES['uploaded']['name']) ; 
 $ok=1;
 if (file_exists($_FILES['uploaded']['tmp_name']))
 {
 echo "Sorry, file already exists.";
 $Ok = 0;}

 //This is our limit file type condition  
 if ($target!=="image/jpg") 
 { 
 echo "You may only upload jpg files.<br>";
 $ok=0;
 }
 //Here we check that $ok was not set to 0 by an error  
 if ($ok==0)  
 {  Echo "Sorry your file was not uploaded";  }  
 //If everything is ok we try to upload it 
 else 
 { 
 if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))  
 {
 echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded"; 
 }  
 else
 {  
 echo "Sorry, there was a problem uploading your file.";  
 } 

}

 ?>

Hi, can you explain your issue? The only problem I see is indentation and the variable $Ok at line 9 which should be $ok, PHP is case sensitive.

It gives this message when i open localhost/tests/admin

Notice: Undefined index: uploaded in C:\wamp\www\test\admin\upload.php on line 4
Call Stack
#   Time    Memory  Function    Location
1   0.1050  136184  {main}( )   ..\addarticle.php:0
2   0.1730  140744  include( 'C:\wamp\www\test\admin\upload.php' )  ..\addarticle.php:3

( ! ) Notice: Undefined index: uploaded in C:\wamp\www\test\admin\upload.php on line 6
Call Stack
#   Time    Memory  Function    Location
1   0.1050  136184  {main}( )   ..\addarticle.php:0
2   0.1730  140744  include( 'C:\wamp\www\test\admin\upload.php' )  ..\addarticle.php:3
You may only upload jpg files.
Sorry your file was not uploaded
Please choose a file: 

It happens because the index $_FILES['uploaded'] is not set, this is defined by the attribute name of your input field:

<input type="file" name="uploaded" />

So check if the value is correct. In any case, in your script you should add a check to verify if the $_FILES array is correctly set, for example:

if(array_key_exists('uploaded', $_FILES))
{
    # run code here
}

It is existing and uploaded is also named correctly.
It is executing all the if commands rest is ok.

Soloved this actually $target = "images/dars/";
i had images folder in root directory changed that to the directory where my admin file is.And also i had mistakes in if commands offcourse.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.