By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,885 Members | 1,469 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,885 IT Pros & Developers. It's quick & easy.

Problem uploading files

pezholio
P: 22
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
Share this Question
Share on Google+
1 Reply


P: 25
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.