Reputation: 4895
Updated!
I have never had a problem with this before, i'm on a local server and UAC is turned off as well.
Here is my form, well, a dumbed down version of the form as there is a lot of text in there:
<form id="setup" name="setup" action="php/process_setup.php" method="post" enctype="multipart/form-data">
<input type="text" name="cname" id="cname" value="" />
<input type="text" name="splash" id="splash" />
<input type="file" name="file"/>
<input type="text" name="email" id="email" />
<input type="password" name="password" id="password" />
<input type="password" name="cpassword" id="cpassword" />
<input type="submit" value="Submit" name="submit_setup" />
</form>
Here is the PHP im trying:
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
And here is the result:
Notice: Undefined index: file in C:\xampp\htdocs\ppa\php\process_setup.php on line 10
Notice: Undefined index: file in C:\xampp\htdocs\ppa\php\process_setup.php on line 16 Upload:
Notice: Undefined index: file in C:\xampp\htdocs\ppa\php\process_setup.php on line 17 Type:
Notice: Undefined index: file in C:\xampp\htdocs\ppa\php\process_setup.php on line 18 Size: 0 kB
Notice: Undefined index: file in C:\xampp\htdocs\ppa\php\process_setup.php on line 19 Stored in:
Edit 2
Just did a test to see if PHP has write permission, here is the code:
echo copy("1383778885275.jpg", "C:/xampp/tmp/1383778885275.jpg");
And the result was:
1
And the image IS in the tmp directory..
Upvotes: 0
Views: 932
Reputation: 4895
Thanks for all the help guys. It seems that there was an issue in some of the code I didn't include.. :/
Basically:
<form id="setup" name="setup" action="php/process_setup.php" method="post" enctype="multipart/form-data">
.....
....
<input type="file" name="logo"/>
...
.....
somewhere had some dodgy code I deleted
....
</form>
Thanks for the help.
Upvotes: 0
Reputation: 8356
According to your notice information ,the $_FILES
is probably empty.You can check the following issues:
1.Make sure your directory has permissions for the tmp and upload directories.
2.Make sure the value of `file_uploads` option in `php.ini` is `On`
Upvotes: 1
Reputation: 10617
You probably need to change !empty($_FILES["file"]["tmp_name"]
to:
isset($_FILES["file"]["tmp_name"]
and if(move_uploaded_file($temp, $location.$name)) {
to:
if(move_uploaded_file($temp, $location.basename($name))) {
Emphasis on basename()
.
Upvotes: 1
Reputation: 3641
I am doing it in on a simple way , try having this:
if(!empty($_POST) && !empty($_FILES["file"]["name"]) ){ //check the following post values if not empty
$name = $_FILES["file"]["name"];
$temp = $_FILES["file"]["tmp_name"];
$location= "../images/";
if(move_uploaded_file($temp, $location.$name)) {
echo "Uploaded!!!";
} else {
echo "Error:";
}
} else {
echo "Please choose a file to upload";
}
Upvotes: 1