I am having file upload issues. So far, I have not been able to upload any files. My server has a Windows 7 32 bit OS. I am running PHP 5.2.17 and Apache 2.2.

This is my index.php page:

<html>
<head>
<title>Upload file</title>
</head>
<body>
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="file" name="pix">
<input type="submit" name="Upload" value="Upload a file">
</form>
</body>
</html>

And, this is the upload.php page that handles file uploads:

<?php
$_FILES['pix']['name'];
move_uploaded_file($_FILES['pix']['tmp_name'], "c:\data");

if (move_uploaded_file($_FILES['pix']['tmp_name'], "c:\data")) 
	{print "Received {$_FILES['pix']['name']}";}

else 
	{print "Upload failed!";}
?>

Every time I attempt to upload a file, the move_uploaded_file command returns false, which throws the string "Upload failed!". I don't see any errors in the Apache or PHP logs. The directory "c:\data" does exist. The file I am attempting to upload is only 500 Kilobytes, and is within the configuration limits in Apache and PHP. Below, I have attached a .ZIP containing my php.ini and http.conf configuration files.

Does anyone have any idea why it returns false? Thanks in advance.

    First, note that this line:

    $_FILES['pix']['name'];

    does absolutely nothing. What is its purpose (or what was it supposed to do)?

    Second, do a [man]phpinfo/man and verify that error_reporting and display_errors match the values that you have in your php.ini file that you attached. If the move is failing, PHP should be emitting an error message with more details.

    Third, note that you aren't telling PHP to move any files into the directory "C:\data\". Instead, you're telling PHP to move the uploaded file to a file called "data" in the root of your C: drive. The second parameter of [man]move_uploaded_file/man should be the full path to the new file - including the new filename.

    EDIT: Also, welcome to PHPBuilder! When posting PHP or HTML code, please use the board's [noparse]

    ..

    or

    ..

    [/noparse] bbcode tags (rather than the generic 'code' tags) as they make your code much easier to read and analyze.

      Display_errors was indeed turned off. Also, thank you for the explanation of the second parameter.

      Thanks for the help! File uploads work just fine now.

        Write a Reply...