When I run this php file it executes everything except the move_uploaded_file. It produces the following Warnings:

warning: move_uploaded_file(uploadsFlowers002.JPG<br>): failed to open stream: Invalid argument in C:\xampp\htdocs\tutorials\filehandeling\upload.php on line 20

Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\php43D.tmp' to 'uploadsFlowers002.JPG<br>' in C:\xampp\htdocs\tutorials\filehandeling\upload.php on line 20

The php file location is C:\xampp\htdocs\tutorials\filehandeling.
The move to location is C:\xampp\htdocs\tutorials\filehandeling\uploads.

I think $location$tmp_name$name are valid declared variables.
So, I don't understand invalid argument on line 20.

I suspect this problem is due to trying to move selected file to the uploads folder.
I've tried the following: $location=C:\xampp\htdocs\tutorials\filehandeling\uploads
$location=C:\xampp\htdocs\tutorials\filehandeling
$location='\uploads';
$location='/uploads';
$location='uploads\';
$location='uploads/';
$location='uploads';

I've also tested with different file type, such as: .txt and got the same warning

Don't know what else to do.

 <html>
    <form action="upload.php" method="POST" enctype="multipart/form-data">
    <input type ="file" name ="file"><br><br>
    <input type ="submit" value="submit">
    </form>
    </html>

<?php
echo 'File name:&nbsp&nbsp&nbsp', $name = $_FILES ['file'] ['name'].'<br>';
echo 'File size:&nbsp&nbsp&nbsp', $size = $_FILES ['file'] ['size'].'&nbsp'.'kb'.'<br>'; 
echo 'File type:&nbsp&nbsp&nbsp', $type = $_FILES ['file'] ['type'].'<br>';
echo 'Temporary file location:&nbsp&nbsp&nbsp',$tmp_name =$_FILES ['file'] ['tmp_name'];

if(isset($name)) {
	if (!empty($name)) {

$location = 'uploads';


if (move_uploaded_file($tmp_name, $location. $name)) {
	echo '<br>File that was <strong><font color="red">UPLOADED</font></strong>';
}	
}	else {
	echo 'Please choose a file';
}
}


?>

Any help would be greatly appreciated.

    PHP is pretty smart about dealing with directory separators in Windows, so you should be able to designate the destination directory with "/" separators (which means you don't have to worry about "\" characters being treated as escape characters), and it will know that they're really "\" in Windows. Also, don't forget you'll need a slash between the directory and the file name. Also, assigning elements of the $FILES array to new scalar variables doesn't really gain you anything (and wastes a tiny amount of resources), so I wouldn't bother, instead doing something like:

    $uploadDir = 'C:/xampp/htdocs/tutorials/filehandeling/uploads/';
    if(!empty($_FILES['file']['tmp_name'])) {
        if(move_uploaded_file($_FILES['file']['tmp_name'], $uploadDir . $_FILES['file']['name']) {
            // success message
        }
        else {
            // error message
        }
    }
    

    (Untested!)

      You would probably have more success if you didn't try to give the file a name ending with "<br>"; '<' and '>' are redirection operators and can't appear in filenames.

      This is alluded to in the second error message where it says that the file couldn't be moved to "uploadsFlowers002.JPG<br>".

        NogDog.
        When I tested the script you provided there was 1 parse error on line 3 of the script. Omitted " ) " after ['name'].
        When I corrected parse error this solution worked perferctly.
        Many thanks.
        I was able to sleep last night.

          Weedpacket.
          Thank you for pointing out the <br> in the error message.
          However the file name does not include <br> when I check the file properties.
          Is it possible that when I run the script it is appending the <br>?
          The only possible place I can see that happening is on line 8. There is a " . " <br> after ['name']
          echo 'File name:&nbsp&nbsp&nbsp', $name = $_FILES ['file'] ['name'].'<br>';

            Yes, that is where it is happening.
            You could replace the concatenation operator ([font=monospace].[/font]) with a comma, as you do elsewhere on the line, but it would be safer to do the assignment and the output as separate statements.

              18 days later

              I found one Best Tutorial for PHP FIle Upload with Preview It was very Helpful Give a Try Once It was very Helpful.
              Thank YOu

                Write a Reply...