file name van image
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
include('imagehandler4.php');
if(!empty($_FILES['file'])){
$error = upload4($_FILES['file']['tmp_name'],'shirts/',$_FILES['file']['name'],800,800);
if($error[0] == true){
echo 'Upload is gelukt';
}else{
echo 'Error: '.$error[2];
}
}else{
echo '
<form enctype="multipart/form-data" method="post" action="upload4.php">
<table border="0"><tr><td>File:</td><td><input type="file" name="file" /></td></tr>
<tr><td> </td><td><input type="submit" value="Upload" /></td></tr>
</table>
</form>';
}
?>
include('imagehandler4.php');
if(!empty($_FILES['file'])){
$error = upload4($_FILES['file']['tmp_name'],'shirts/',$_FILES['file']['name'],800,800);
if($error[0] == true){
echo 'Upload is gelukt';
}else{
echo 'Error: '.$error[2];
}
}else{
echo '
<form enctype="multipart/form-data" method="post" action="upload4.php">
<table border="0"><tr><td>File:</td><td><input type="file" name="file" /></td></tr>
<tr><td> </td><td><input type="submit" value="Upload" /></td></tr>
</table>
</form>';
}
?>
ik wil het opslaan in een database, dus als het plaatje test.jpg is moet er ook test.jpg in de database komen, ik doe het nu als volgt:
$functie = mysql_query("INSERT INTO shirts (bestandsnaam) VALUES ('$file') ") or die (mysql_error());
maar met $file krijg ik een hele vreemde code in de database, zoiets als dit:
/tmp/phpxDqE8c
de code van imagehandler4.php (wat geinclude wordt) is als volgt:
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
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
<?php
//function to resize / upload a photo save it to a dir
function upload4 ($tempfile,$dir,$file,$height,$width){
//$tempfile = filename generated by the server when uploading a file
//$dir = directory with the final location
//$file = new filename
//$height / $width explain enough i think
//check if the file is realy uploaded
if(!is_uploaded_file($tempfile)){
$error[0] = false;
$error[1] = -1;
$error[2] = 'file is not uploaded';
return $error;
}else{
//get the dimensions of the file
if(!$dim = getimagesize($tempfile)){
$error[0] = false;
$error[1] = -2;
$error[2] = 'No image file';
return $error;
}else{
//0 = width
//1 = height
//2 = type
//we want to calculte if the bigger then the maxsize if not keep it easy --> upload it
//we have to resize :(
$dims[0] = 375;
$dims[1] = 335;
//we know the new size
if($dim[2] == 2){
if(!$mimage = @imagecreatefromjpeg($tempfile)){
$error[0] = false;
$error[1] = -4;
$error[2] = 'Error';
return $error;
}
$im = @imagecreatetruecolor($dims[0],$dims[1]);
@imagecopyresampled($im, $mimage, 0, 0, 0, 0, $dims[0], $dims[1], $dim[0], $dim[1]);
if(!file_exists($dir.$file)){
if($dim[2] == 2){
if(!@imagejpeg($im,$dir.$file,100)){
$error[0] = false;
$error[1] = -5;
$error[2] = 'Imagecreate error';
return $error;
}else{
$error[0] = true;
$error[1] = 2;
$error[2] = 'Resized';
return $error;
}
}
}else{
$error[0] = false;
$error[1] = -4;
$error[2] = 'File allready exsits';
return $error;
}
imagedestroy($im);
imagedestroy($mimage);
//end resize
}
}
}
}
?>
//function to resize / upload a photo save it to a dir
function upload4 ($tempfile,$dir,$file,$height,$width){
//$tempfile = filename generated by the server when uploading a file
//$dir = directory with the final location
//$file = new filename
//$height / $width explain enough i think
//check if the file is realy uploaded
if(!is_uploaded_file($tempfile)){
$error[0] = false;
$error[1] = -1;
$error[2] = 'file is not uploaded';
return $error;
}else{
//get the dimensions of the file
if(!$dim = getimagesize($tempfile)){
$error[0] = false;
$error[1] = -2;
$error[2] = 'No image file';
return $error;
}else{
//0 = width
//1 = height
//2 = type
//we want to calculte if the bigger then the maxsize if not keep it easy --> upload it
//we have to resize :(
$dims[0] = 375;
$dims[1] = 335;
//we know the new size
if($dim[2] == 2){
if(!$mimage = @imagecreatefromjpeg($tempfile)){
$error[0] = false;
$error[1] = -4;
$error[2] = 'Error';
return $error;
}
$im = @imagecreatetruecolor($dims[0],$dims[1]);
@imagecopyresampled($im, $mimage, 0, 0, 0, 0, $dims[0], $dims[1], $dim[0], $dim[1]);
if(!file_exists($dir.$file)){
if($dim[2] == 2){
if(!@imagejpeg($im,$dir.$file,100)){
$error[0] = false;
$error[1] = -5;
$error[2] = 'Imagecreate error';
return $error;
}else{
$error[0] = true;
$error[1] = 2;
$error[2] = 'Resized';
return $error;
}
}
}else{
$error[0] = false;
$error[1] = -4;
$error[2] = 'File allready exsits';
return $error;
}
imagedestroy($im);
imagedestroy($mimage);
//end resize
}
}
}
}
?>
Gewijzigd op 01/01/1970 01:00:00 door Timor bos
Code (php)
1
2
3
2
3
<?php
$functie = mysql_query("INSERT INTO shirts (bestandsnaam) VALUES ('".$file."') ") or die (mysql_error());
?>
$functie = mysql_query("INSERT INTO shirts (bestandsnaam) VALUES ('".$file."') ") or die (mysql_error());
?>
zou het moeten zijn. Verder hoe kom je aan $file?
/tmp/phpUI0rnw
file zou de nieuwe file name moeten zijn volgens de uitleg van het script.. snapt iemand dit?
ben niet echt goed in php
thanx!