471,321 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,321 software developers and data experts.

Problem uploading files


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:


$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 ++;



$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 ++;


Any ideas?

Jun 25 '08 #1
1 1978
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">
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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.