file in root uplauden
ik heb een script om files up te loaden in mn root, maar de hele tijd krijg ik de foutmelding: "invalid file"
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<head>
<?php
$allowedExts = array("jpg", "jpeg", "gif", "png", "mp3", "mp4", "wma");
$extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
if ((($_FILES["file"]["type"] == "video/mp4")
|| ($_FILES["file"]["type"] == "audio/mp3")
|| ($_FILES["file"]["type"] == "audio/wma")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_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 "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
<title></title>
</head>
<body>
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<label for="file"><span>Filename:</span></label>
<input type="file" name="file" id="file" >
<br />
<input type="submit" name="submit" value="Submit" >
</form>
<?php var_dump($_FILES); ?>
</body>
</html>
<head>
<?php
$allowedExts = array("jpg", "jpeg", "gif", "png", "mp3", "mp4", "wma");
$extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
if ((($_FILES["file"]["type"] == "video/mp4")
|| ($_FILES["file"]["type"] == "audio/mp3")
|| ($_FILES["file"]["type"] == "audio/wma")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_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 "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
<title></title>
</head>
<body>
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<label for="file"><span>Filename:</span></label>
<input type="file" name="file" id="file" >
<br />
<input type="submit" name="submit" value="Submit" >
</form>
<?php var_dump($_FILES); ?>
</body>
</html>
Kan iemand me verder helpen?
Met vriendelijke groet,
Fabian http://web-stars.nl
Misschien heb je geen rechten om naar die map bestanden uploaden.
Toevoeging op 06/10/2015 16:42:06:
@maarten hij staat op 777
Toevoeging op 06/10/2015 16:42:45:
var_dump: array(1) { ["file"]=> array(5) { ["name"]=> string(19) "Abba - Fernando.mp3" ["type"]=> string(10) "audio/mpeg" ["tmp_name"]=> string(14) "/tmp/phpqK4KT9" ["error"]=> int(0) ["size"]=> int(4085306) } }
Dat zal goed moeten zijn lijkt mij.
Toevoeging op 06/10/2015 16:44:32:
PHP Maarten op 06/10/2015 16:42:52:
Dat zal goed moeten zijn lijkt mij.
Staat los van de rechten. Het gebruikte mimetype en de extentie komt niet overeen met de array.
Gewijzigd op 06/10/2015 16:45:14 door - Ariën -
Array ( [file] => Array ( [name] => Abba Dancing Queen lyrics.mp3 [type] => audio/mpeg [tmp_name] => /tmp/phpNgrR88 [error] => 0 => 3584152 ) )
Ja, zie mijn vorige post.
Quote:
Het gebruikte mimetype en de extentie komt niet overeen met de array.
audio/mpeg dit klopt niet toch?
Wat bedoel je met mimetype ?
Toevoeging op 06/10/2015 16:53:55:
hey het is bij een foto nu wel gelukt..
Gewijzigd op 06/10/2015 16:52:08 door Fabian webstars
audio/mpeg wordt nu nog dus geweigerd omdat hij nog niet in de de if-voorwaarde staat.
Gewijzigd op 06/10/2015 16:56:58 door Fabian webstars