Hi!
I have been here before a few days ago with a similar problem, but have changed the upload script in the mean time.
I'm using WS_FTP LE and have "Read" and "Write" permissions as "Owner" to the directory where the file should be uploaded to.
When I try to upload a correct file, I get the "Could not upload the file"-error message and nothing is uploaded.
When I try to upload a file that is e.g. too big I get the right error message and the file is rejected as it should.
In the error log on the web-server:
PHP Warning: Unable to create '/docs/grafik/bands/test.jpg': No such file or directory in ///www.mysite.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\">
...
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");
}
I am very confused!
Thanks
Ole