upload
HejJeg bruger WS_FTP LE og har "Read" og "Write" rettigheder som "Owner" til det directory, som filen skal uploades til. Dir'et "bands" eksistere naturligvis.
Når jeg forsøger at uploade en korrekt fil, får jeg "Could not upload the file" tilbage, altså die()-statement'en.
Når jeg forsøger at uploade en Ukorrekt fil, fx. en som er for stor, får jeg den rigtige fejl-medl. tilbage.
I error-loggen på web-serveren kan jeg læse efter at have forsøgt at uploade test.jpg:
PHP Warning: Unable to create '/docs/grafik/bands/test.jpg': No such file or directory in /**/**/www.minside.dk/docs/admin/action.php on line 92
picture.php:
...
<FORM METHOD=\"post\" ACTION=\"action.php\" enctype=\"multipart/form-data\">
...
<INPUT TYPE=\"file\" NAME=\"img\" SIZE=\"79\">
...
<INPUT TYPE=\"submit\" NAME=\"ins_pict\" VALUE=\"Upload\">
...
Og action.php:
IF($_POST['ins_pict']) {
$ins_pict=$_POST['ins_pict'];
$id=$_POST['id'];
$allowedTypes = array("image/jpeg", "image/pjpeg", "image/jpg"); //allowed file types
$maxFileSize = 30720; //max size in bytes
$maxImgWidth = 200; //max width in pixels
IF($_FILES['img']['tmp_name']!= '') {
/* -- -- if img-input-field ok -- -- */
//File type allowed?
IF (in_array($_FILES['img']['type'],$allowedTypes)) {
//Size allowed?
IF ($_FILES['img']['size'] <= $maxFileSize) {
//What is the width?
$size = getImageSize($_FILES['img']['tmp_name']);
list($foo, $width, $bar, $height) = explode("\"",$size[3]);
//Width allowed?
IF ($width <= $maxImgWidth) {
$path = "/docs/grafik/bands";//*nix-path
copy($_FILES['img']['tmp_name'], $path."/".$_FILES['img']['name']) or die("Could not upload file");
unlink($_FILES['img']['tmp_name']);
$mess = "Picture added!";
}
ELSE {
//Error mess. if pict too big
$mess = "Picture NOT added. It is too big!";
}
}
ELSE {
//Error mess. if file too big
$mess = "Picture NOT added. The file is too big!";
}
}
ELSE {
//Error mess. if file type not allowed
$mess = "Picture NOT added. The file type is not allowed!";
}
}
ELSE {
//Error mess. if input field empty
$mess = "Picture NOT added. File not specified!";
}
Header("Location:picture.php?id=$id&mess=$mess");
}
Jeg er MEGET forvirret!
Mvh.
1409
