Jump to content

Archived

This topic is now archived and is closed to further replies.

mistakes!

file upload

Recommended Posts

hello i am trying to run this file upload form and it outputs the following error
There was a error in uploading please try again..Sorry unable to connect to the database..
the paper directory is a folder inside a folder where i will like to store all uploaded files, pls any ideas why it is not working?
[code]
$dir="papers/";
$area=$_POST['area'];
$event=$_POST['event']; //take values from previous file.
$filename=basename($_FILES['paper']['name']);
$dir=$dir.basename($_FILES['paper']['name']);
$ext= explode('.',$filename);
$ext = $ext[count($ext)-1];
if($ext==='doc' || $ext==='pdf') //check if the file is doc.
  {
     if(move_uploaded_file($_FILES['paper']['tmp_name'],$dir)) //move the file to papers directory.
      {
         print("The file as been uploaded");
      }
      else
      {
        print("There was a error in uploading please try again..");
      }
      $link = mysql_connect("localhost" , "outreach") or die("Could not connect to the database");
[/code]
pls help me

Share this post


Link to post
Share on other sites
first one must remember the title Guru is like an honorary degree, it doesn't mean I know anything. That said, I am not sure this is the root of your problem; however, if we take this portion of your script...

[code]
if($ext==='doc' || $ext==='pdf') //check if the file is doc.
  {
     if(move_uploaded_file($_FILES['paper']['tmp_name'],$dir)) //move the file to papers directory.
      {
         print("The file as been uploaded");
      }
      else
      {
        print("There was a error in uploading please try again..");
      }[/code]

and remove all the comments, plus do some careful indenting like so...

[code]if($ext==='doc' || $ext==='pdf'){
    if(move_uploaded_file($_FILES['paper']['tmp_name'],$dir)) {
        print("The file as been uploaded");
    }else{
        print("There was a error in uploading please try again..");
    }[/code]

It would appear that you are missin gyour final brace, and that may be a part of the problem.

Lite...

Share this post


Link to post
Share on other sites
Boss although you need help and we ppl try to workout on your problems and you are showing such attitude that the snippet will help... Too bad..
Show some more code and explain some more on the problem...
[!--quoteo(post=373158:date=May 11 2006, 08:02 AM:name=mistakes!)--][div class=\'quotetop\']QUOTE(mistakes! @ May 11 2006, 08:02 AM) [snapback]373158[/snapback][/div][div class=\'quotemain\'][!--quotec--]
sorry do u mean the whole code?
[/quote]

Share this post


Link to post
Share on other sites
I had a similar problem with the move_uploaded_file

temporarily, set the permissions of the dir that you are moving the file to, to 777

that was a problem I had, the dir did not have permissions to be written to

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.