Uploaden vanaf URL
Hij geeft opzich geen errors, maar hij zet hem niet op mijn server.
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
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
<?php
//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","10000");
//This function reads the extension of the file. It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
//This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an errro occures.
//If the error occures the file will not be uploaded.
$errors=0;
//checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['text']['name'];
//if it is not empty
if ($image)
{
//get the original name of the file from the clients machine
$filename = stripslashes($_FILES['text']['name']);
//get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file,
//otherwise we will do more tests
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
//print error message
echo '<h1>Verkeerde extensie!</h1>';
$errors=1;
}
else
{
//get the size of the image in bytes
//$_FILES['image']['tmp_name'] is the temporary filename of the file
//in which the uploaded file was stored on the server
$size=filesize($_FILES['text']['tmp_name']);
//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*50000000)
{
echo '<h1>U heeft de maximale grootte overschreden!</h1>';
$errors=1;
}
//we will give an unique name, for example the time in unix time format
$image_name=time().'.'.$extension;
//the new name will be containing the full path where will be stored (images folder)
$newname="images/".$image_name;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['text']['tmp_name'], $newname);
if (!$copied)
{
echo '<h1>Kopiëren mislukt!</h1>';
$errors=1;
}}}}
//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
echo "<h1>Uw bestand is succesvol geupload.</h1><br>URL: http://powarimages.netii.net/images/$image_name";
}
?>
//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","10000");
//This function reads the extension of the file. It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
//This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an errro occures.
//If the error occures the file will not be uploaded.
$errors=0;
//checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['text']['name'];
//if it is not empty
if ($image)
{
//get the original name of the file from the clients machine
$filename = stripslashes($_FILES['text']['name']);
//get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file,
//otherwise we will do more tests
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
//print error message
echo '<h1>Verkeerde extensie!</h1>';
$errors=1;
}
else
{
//get the size of the image in bytes
//$_FILES['image']['tmp_name'] is the temporary filename of the file
//in which the uploaded file was stored on the server
$size=filesize($_FILES['text']['tmp_name']);
//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*50000000)
{
echo '<h1>U heeft de maximale grootte overschreden!</h1>';
$errors=1;
}
//we will give an unique name, for example the time in unix time format
$image_name=time().'.'.$extension;
//the new name will be containing the full path where will be stored (images folder)
$newname="images/".$image_name;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['text']['tmp_name'], $newname);
if (!$copied)
{
echo '<h1>Kopiëren mislukt!</h1>';
$errors=1;
}}}}
//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
echo "<h1>Uw bestand is succesvol geupload.</h1><br>URL: http://powarimages.netii.net/images/$image_name";
}
?>
<!--next comes the form, you must set the enctype to "multipart/frm-data" and use an input type "text" -->
<form name="newad" method="post" enctype="multipart/form-data" action="">
<table>
<tr><td><input type="text" name="image"></td></tr>
<tr><td><input name="Submit" type="submit" value="Upload afbeelding"></td></tr>
</table>
</form>
Link: http://powarimages.netii.net/uploader2.php
ge-CHmod?
Ofcourse.
Er is geen input type = "file".
Zet error_reporting(E_ALL) eens aan.
Edit:
Bij jouw gastenboek staat: Bug in het tijdssysteem geconstateerd.
Dat is geen bug, maar je zit in een andere tijdzone.
Standard time zone: UTC/GMT +2 hours
Daylight saving time: +1 hour
Current time zone offset: UTC/GMT +3 hours
Time zone abbreviation: EEST - Eastern European Summer Time
Dat is geen bug, maar je zit in een andere tijdzone.
Standard time zone: UTC/GMT +2 hours
Daylight saving time: +1 hour
Current time zone offset: UTC/GMT +3 hours
Time zone abbreviation: EEST - Eastern European Summer Time
Gewijzigd op 27/06/2010 14:53:36 door - SanThe -
En hoe/waar zet ik error_reporting aan?
Over gastenboek:
$time = date(h .':' . i .':' . s); //tijd van verzenden
$date = date(j .' '. M .' '. Y); //datum van verzenden
Waar stel ik GMT in?
Edit:
Als je niks invult en upload dan geeft hij geen error.
Terwijl dit erin staat:
//reads the name of the file the user submitted for uploading
$image=$_FILES['text']['name'];
//if it is not empty
if ($image)
Terwijl dit erin staat:
//reads the name of the file the user submitted for uploading
$image=$_FILES['text']['name'];
//if it is not empty
if ($image)
Nog iets:
Upload script vanaf PC (daarvan probeer ik deze af te leiden):
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
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
<?php
//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","10000");
//This function reads the extension of the file. It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
//This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an errro occures.
//If the error occures the file will not be uploaded.
$errors=0;
//checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
//if it is not empty
if ($image)
{
//get the original name of the file from the clients machine
$filename = stripslashes($_FILES['image']['name']);
//get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file,
//otherwise we will do more tests
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
//print error message
echo '<h1>Verkeerde extensie!</h1>';
$errors=1;
}
else
{
//get the size of the image in bytes
//$_FILES['image']['tmp_name'] is the temporary filename of the file
//in which the uploaded file was stored on the server
$size=filesize($_FILES['image']['tmp_name']);
//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*50000000)
{
echo '<h1>U heeft de maximale grootte overschreden!</h1>';
$errors=1;
}
//we will give an unique name, for example the time in unix time format
$image_name=time().'.'.$extension;
//the new name will be containing the full path where will be stored (images folder)
$newname="images/".$image_name;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<h1>Kopiëren mislukt!</h1>';
$errors=1;
}}}}
//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
echo "<h1>Uw bestand is succesvol geupload.</h1><br>URL: http://powarimages.netii.net/images/$image_name";
}
?>
//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","10000");
//This function reads the extension of the file. It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
//This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an errro occures.
//If the error occures the file will not be uploaded.
$errors=0;
//checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
//if it is not empty
if ($image)
{
//get the original name of the file from the clients machine
$filename = stripslashes($_FILES['image']['name']);
//get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file,
//otherwise we will do more tests
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
//print error message
echo '<h1>Verkeerde extensie!</h1>';
$errors=1;
}
else
{
//get the size of the image in bytes
//$_FILES['image']['tmp_name'] is the temporary filename of the file
//in which the uploaded file was stored on the server
$size=filesize($_FILES['image']['tmp_name']);
//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*50000000)
{
echo '<h1>U heeft de maximale grootte overschreden!</h1>';
$errors=1;
}
//we will give an unique name, for example the time in unix time format
$image_name=time().'.'.$extension;
//the new name will be containing the full path where will be stored (images folder)
$newname="images/".$image_name;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<h1>Kopiëren mislukt!</h1>';
$errors=1;
}}}}
//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
echo "<h1>Uw bestand is succesvol geupload.</h1><br>URL: http://powarimages.netii.net/images/$image_name";
}
?>
<!--next comes the form, you must set the enctype to "multipart/frm-data" and use an input type "file" -->
<form name="newad" method="post" enctype="multipart/form-data" action="">
<table>
<tr><td><input type="file" name="image"></td></tr>
<tr><td><input name="Submit" type="submit" value="Upload afbeelding"></td></tr>
</table>
</form>
Gewijzigd op 27/06/2010 14:10:15 door peter dhc
Code (php)
1
2
3
4
5
6
2
3
4
5
6
<?php
ini_set('display_errors', 1); // 0 = uit, 1 = aan
error_reporting(E_ALL);
// rest
?>
ini_set('display_errors', 1); // 0 = uit, 1 = aan
error_reporting(E_ALL);
// rest
?>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
}
//This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an errro occures.
//If the error occures the file will not be uploaded.
$errors=1;
//checks if the form has been submitted
if(isset($_POST['Submit']))
//print error message
echo '<h1>Niks ingevuld!</h1>';
{
//This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an errro occures.
//If the error occures the file will not be uploaded.
$errors=1;
//checks if the form has been submitted
if(isset($_POST['Submit']))
//print error message
echo '<h1>Niks ingevuld!</h1>';
{
Maar kan iemand mij nog helpen met het $_FILES probleem?
Quote:
Maar waar verwijst $_FILES nu dan naar input type = "file"?
Gewijzigd op 27/06/2010 14:50:44 door peter dhc
Nino van den Bosch op 27/06/2010 14:43:32:
... hij geeft nu altijd die error weer ...
Welke error?
//This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an errro occures.
//If the error occures the file will not be uploaded.
$errors=1;
//checks if the form has been submitted
if(isset($_POST['Submit']))
//print error message
echo '<h1>Niks ingevuld!</h1>';
{
$_FILES zal niet gevuld zijn.
Er is geen input type = "file".
Dat onderwerp dwaalt af!
Euhm... gebruiker voert in het text veld een url in, klikt op submit, vervolgens laat je de server het betreffende bestand ophalen. Dat is wat je wil, volg ik het zo goed? In dat geval heeft het niks met uploaden te maken en is $_FILES ook helemaal niet van toepassing.
Piet Verhagen op 27/06/2010 16:24:30:
Euhm... gebruiker voert in het text veld een url in, klikt op submit, vervolgens laat je de server het betreffende bestand ophalen. Dat is wat je wil, volg ik het zo goed? In dat geval heeft het niks met uploaden te maken en is $_FILES ook helemaal niet van toepassing.
Ja, en dan zet hij het bestand in mijn ./images mapje.
SanThe Nvt op 27/06/2010 15:49:20:
Dit is geen error maar code.
Welke error?
Welke error?
Edit:
Niet bumpen.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
}
//This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an errro occures.
//If the error occures the file will not be uploaded.
$errors=1;
//checks if the form has been submitted
if(isset($_POST['Submit']))
//print error message
echo '<h1>Niks ingevuld!</h1>';
{
//This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an errro occures.
//If the error occures the file will not be uploaded.
$errors=1;
//checks if the form has been submitted
if(isset($_POST['Submit']))
//print error message
echo '<h1>Niks ingevuld!</h1>';
{