468,765 Members | 817 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

Problem uploading files

pezholio
Hi,

It seems that every time I put together a new script to upload a file I always have problems, here's the latest one:

I've got a form with two file input fields, when I submit the form, everything goes OK, but the files don't upload, the permissions on the folders are fine and dandy (Both 777). Here's my code:

[PHP]if(is_uploaded_file($_FILES['image']['tmp_name'])){

$target_path = "/home/default/ratemyplace.org.uk/user/htdocs/newsite/images/premimages/";

$target_path = $target_path . basename( $_FILES['image']['name']);

$ext = substr($_FILES['image']['name'], strrpos($_FILES['image']['name'], '.') + 1);
$ext = strtoupper($ext);

if ($ext != "JPG"|"JPEG"|"GIF"|"PNG") {
$errorarray[] = "<li><a href='#image'>Sorry, you can only upload images in .jpg, .gif or .png format</a> $ext</li>";
$error ++;
} else {

if(move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {
$image = basename( $_FILES['image']['name']);
} else{
$errorarray[] = "<li><a href='#image'>There was an error uploading your image, please try again</a></li>";
$error ++;
}
}

}

if(is_uploaded_file($_FILES['report']['tmp_name'])){

$target_path = "/home/default/ratemyplace.org.uk/user/htdocs/newsite/uploads/";

$target_path = $target_path . basename( $_FILES['report']['name']);

$ext = substr($_FILES['report']['name'], strrpos($_FILES['report']['name'], '.') + 1);
$ext = strtoupper($ext);

if ($ext != "PDF"|"DOC") {
$errorarray[] = "<li><a href='#report'>Sorry, you can only upload reports in .pdf or .doc format</a></li>";
$error ++;
} else {

if(move_uploaded_file($_FILES['report']['tmp_name'], $target_path)) {
$report = basename( $_FILES['report']['name']);
} else{
$errorarray[] = "<li><a href='#report'>There was an error uploading your report, please try again</a></li>";
$error ++;
}
}

}
[/PHP]

Any ideas?

Cheers
Jun 25 '08 #1
1 1918
Have you add enctype to your form? it looks like this:

Expand|Select|Wrap|Line Numbers
  1. <form enctype="multipart/form-data" action="somefile.php" method="post">
  2.  
Jun 25 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Mike Walsh | last post: by
reply views Thread by FusionGuy | last post: by
15 posts views Thread by =?ISO-8859-1?Q?J=F8rn?= Dahl-Stamnes | last post: by
3 posts views Thread by dreamznatcher | last post: by
7 posts views Thread by jambroo | last post: by
2 posts views Thread by =?Utf-8?B?TmV0YWpp?= | last post: by
3 posts views Thread by muziburrehaman | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.