472,958 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 2072
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

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

Similar topics

3
by: Mike Walsh | last post by:
I have a problem uploading files with PHP which has me stumped! I am unable to successfully upload files. My simple test script is as follows: <?php if (count($_FILES)) { var_dump($_FILES)...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
4
by: Himanshu | last post by:
hi, Can anybody tell me that thru asp.net using c#, how can we upload and download physical files in any table of SQL Server Database. the uploading part is running successfully but the...
0
by: FusionGuy | last post by:
I've created a file uploading handler, implemented as an httpHandler. Each time I attempt to upload a file, or files, my HttpContext.Request.Files property never contains the files that were...
15
by: =?ISO-8859-1?Q?J=F8rn?= Dahl-Stamnes | last post by:
Hello folks, I need some help/advice FAST. I have problems with addslashes on my web-servers. After uploading a file, I read the uploaded file, use addslashes on the read data and then insert...
3
by: dreamznatcher | last post by:
Hello, I found a script here: http://www.webtoolkit.info/ajax-file-upload.html which supposedly allows you to upload files using AJAX (I'm not an expert). The site claims it's the best way to...
7
by: jambroo | last post by:
Hello, We are currently having issues uploading files using PHP. It seems files below 8MB are uploaded fine, however files above 8.2MB cause the page to timeout or show a 'Cannot find server or...
2
by: Zoliq | last post by:
Hi, I have a serious problem. I'm currently developing an application in which the user should upload many files (600-700 xml files). I've searched the web for a while and so far I realized that...
2
by: =?Utf-8?B?TmV0YWpp?= | last post by:
Hi Experts We are uploading files on the server using HtmlInputfile control with visual studio 2005, 2.0. In this there is an option for user to keep on uploading the files finally file actually...
3
by: muziburrehaman | last post by:
i am looking for code in php to upload the 1 gb files. any one can please help me by sending the code....
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.