Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem uploading files

pezholio's Avatar
Newbie
 
Join Date: Jun 2007
Posts: 22
#1: Jun 25 '08
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

Newbie
 
Join Date: Jun 2008
Posts: 25
#2: Jun 25 '08

re: Problem uploading files


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.  
Reply