file upload werkt niet
hieronder staat mijn script. Het werkt wel indien geen plaatje wordt toegevoegd. Als de gebruiker een plaatje toevoegd werkt het echter niet. Iemand enig idee?
alvast bedankt!
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?
if (isset($_POST['add'])) //kijken of er iets meekomt met URL
{
if (isset($_POST['title']) && $_POST['catalogue_number'] && $_POST['price'] && $_POST['shipping_costs'] && $_POST['description'] && $_POST['condition'])
{
$title = htmlentities($_POST['title']);
$title = ucfirst($title);
$cat = htmlentities($_POST['catalogue_number']);
$cat = ucfirst($cat);
$price = htmlentities($_POST['price']);
$shipping = htmlentities($_POST['shipping_costs']);
$description = htmlentities($_POST['description']);
if (!($_FILES['file']['name']))
{
$filename=TRUE;
unset ($filename);
}
else
{
$filename = $_FILES['file']['name'];
}
if (check_length($title, 15))
{
echo "Title field has to be at least 15 characters<br><a href=\"#\" onclick=\"history.go(-1)\">back</a></script>";
}
elseif (check_length($description, 75))
{
echo "Description field has to be at least 75 characters<br><a href=\"#\" onclick=\"history.go(-1)\">back</a></script>";
}
elseif (!is_numeric($price))
{
echo "Please enter your price in numbers: 29,95 is valid. Every input with letters is false";
}
elseif (!is_numeric($shipping))
{
echo "Please enter the shipping costs in numbers: 29,95 is valid. Every input with letters is false";
}
elseif(isset($filename))
{
$size = $_FILES['file']['size'];
$extensie = substr($filename, -3);
if (strtoupper($extensie) != "JPG" && strtoupper($extensie) != "GIF" && strtoupper($extensie) != "JPEG")
{
echo "Only JPG or GIF files can be used!<br><script><a href=\"#\" onclick=\"history.go(-1)\">back</a>')</script>";
}
elseif ($size > 51200)
{
echo "Only JPG, JPEG or GIF files can be used!<br><script><a href=\"#\" onclick=\"history.go(-1)\">back</a>')</script>";
}
}
// plaats het oproepje
elseif (isset($_POST['add']))
{
if (isset($filename))
{
$filename = $_FILES['file']['name'];
$destination = "/home/tineau/public_html/images/ad_images/";
$length = strlen($filename);
$name = "ad_images";
// $name = substr($filename, 0, $length - 4);
$i = 0;
$tempname = $name;
// Check of file al bestaat, zo ja, filename 'verhogen'
while (file_exists($destination . $tempname . $i . ".".$extensie))
{
$i = $i + 1;
}
$name = $name . $i;
move_uploaded_file($file, $destination . $name . ".".$extensie);
$bestand="$name"."."."$extensie";
}
else
{
$bestand='';
}
$description = parse1($description);
$datum = date("D M j G:i:s T Y");
$sql = "insert into sell_list (sell_id, login, title, catalogue_number, price, shipping_cost, description, condition, image_path, date) VALUES ('', '$_SESSION[login]', '$title', '$cat', '$price', '$shipping', '$description', '$_POST[condition]', '$bestand', '$datum')";
$res = mysql_query($sql);
if ($res)
{
echo"Succes";
}
else
{
echo"Failure";
}
}
}
else
{
echo "You have not completely filled in all fields,<br> Go back and try again!<br><a href=\"#\" onclick=\"history.go(-1)\">back</a></script>";
}
}
?>
if (isset($_POST['add'])) //kijken of er iets meekomt met URL
{
if (isset($_POST['title']) && $_POST['catalogue_number'] && $_POST['price'] && $_POST['shipping_costs'] && $_POST['description'] && $_POST['condition'])
{
$title = htmlentities($_POST['title']);
$title = ucfirst($title);
$cat = htmlentities($_POST['catalogue_number']);
$cat = ucfirst($cat);
$price = htmlentities($_POST['price']);
$shipping = htmlentities($_POST['shipping_costs']);
$description = htmlentities($_POST['description']);
if (!($_FILES['file']['name']))
{
$filename=TRUE;
unset ($filename);
}
else
{
$filename = $_FILES['file']['name'];
}
if (check_length($title, 15))
{
echo "Title field has to be at least 15 characters<br><a href=\"#\" onclick=\"history.go(-1)\">back</a></script>";
}
elseif (check_length($description, 75))
{
echo "Description field has to be at least 75 characters<br><a href=\"#\" onclick=\"history.go(-1)\">back</a></script>";
}
elseif (!is_numeric($price))
{
echo "Please enter your price in numbers: 29,95 is valid. Every input with letters is false";
}
elseif (!is_numeric($shipping))
{
echo "Please enter the shipping costs in numbers: 29,95 is valid. Every input with letters is false";
}
elseif(isset($filename))
{
$size = $_FILES['file']['size'];
$extensie = substr($filename, -3);
if (strtoupper($extensie) != "JPG" && strtoupper($extensie) != "GIF" && strtoupper($extensie) != "JPEG")
{
echo "Only JPG or GIF files can be used!<br><script><a href=\"#\" onclick=\"history.go(-1)\">back</a>')</script>";
}
elseif ($size > 51200)
{
echo "Only JPG, JPEG or GIF files can be used!<br><script><a href=\"#\" onclick=\"history.go(-1)\">back</a>')</script>";
}
}
// plaats het oproepje
elseif (isset($_POST['add']))
{
if (isset($filename))
{
$filename = $_FILES['file']['name'];
$destination = "/home/tineau/public_html/images/ad_images/";
$length = strlen($filename);
$name = "ad_images";
// $name = substr($filename, 0, $length - 4);
$i = 0;
$tempname = $name;
// Check of file al bestaat, zo ja, filename 'verhogen'
while (file_exists($destination . $tempname . $i . ".".$extensie))
{
$i = $i + 1;
}
$name = $name . $i;
move_uploaded_file($file, $destination . $name . ".".$extensie);
$bestand="$name"."."."$extensie";
}
else
{
$bestand='';
}
$description = parse1($description);
$datum = date("D M j G:i:s T Y");
$sql = "insert into sell_list (sell_id, login, title, catalogue_number, price, shipping_cost, description, condition, image_path, date) VALUES ('', '$_SESSION[login]', '$title', '$cat', '$price', '$shipping', '$description', '$_POST[condition]', '$bestand', '$datum')";
$res = mysql_query($sql);
if ($res)
{
echo"Succes";
}
else
{
echo"Failure";
}
}
}
else
{
echo "You have not completely filled in all fields,<br> Go back and try again!<br><a href=\"#\" onclick=\"history.go(-1)\">back</a></script>";
}
}
?>
foutmeldingen enz?
"plaatjes en php" ---> "uploaden" ---> "uploadfolder" ---> "chmod" ---> "(0)777"
Met andere woorden; is de destination folder ge-chmod naar 777? Met chmod() moet je 0777 gebruiken zoals je weet.
Code (php)
1
2
3
4
2
3
4
<?
$extensie = substr($filename, -3);
if (strtoupper($extensie) != "JPG" && strtoupper($extensie) != "GIF" && strtoupper($extensie) != "JPEG")
?>
$extensie = substr($filename, -3);
if (strtoupper($extensie) != "JPG" && strtoupper($extensie) != "GIF" && strtoupper($extensie) != "JPEG")
?>
Extensie van een bestand kan ook .js zijn ofzo.. Dan krijg jij als extensie .js ipv js. Ook is het argument $extensie != 'JPEG' zinloos omdat je extensie op jou manier altijd 3 karakters is en nooit JPEG kan zijn..
Als je een bestand geupload heb staat in $_FILES['file']['type'] het bestandstype al...
Dutchcamel bedankt voor je tip :)
Het probleem ligt hier volgens mij:
Het script checkt eerst of alles klopt maar hij loopt vast in de laatste elseif-lus indien er een plaatje bijzit.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?
elseif (!is_numeric($shipping))
{
echo "Please enter the shipping costs in numbers: 29,95 is valid. Every input with letters is false";
}
elseif(isset($filename)) // hier komt het script niet meer uit denk ik!!
{
$size = $_FILES['file']['size'];
$extensie = substr($filename, -3);
if (strtoupper($extensie) != "JPG" && strtoupper($extensie) != "GIF")
{
echo "Only JPG or GIF files can be used!<br><script><a href=\"#\" onclick=\"history.go(-1)\">back</a>')</script>";
}
elseif ($size > 51200)
{
echo "Only JPG, JPEG or GIF files can be used!<br><script><a href=\"#\" onclick=\"history.go(-1)\">back</a>')</script>";
}
}
?>
elseif (!is_numeric($shipping))
{
echo "Please enter the shipping costs in numbers: 29,95 is valid. Every input with letters is false";
}
elseif(isset($filename)) // hier komt het script niet meer uit denk ik!!
{
$size = $_FILES['file']['size'];
$extensie = substr($filename, -3);
if (strtoupper($extensie) != "JPG" && strtoupper($extensie) != "GIF")
{
echo "Only JPG or GIF files can be used!<br><script><a href=\"#\" onclick=\"history.go(-1)\">back</a>')</script>";
}
elseif ($size > 51200)
{
echo "Only JPG, JPEG or GIF files can be used!<br><script><a href=\"#\" onclick=\"history.go(-1)\">back</a>')</script>";
}
}
?>
Gewijzigd op 11/08/2004 20:46:00 door tineau
bedankt voor de hulp