Page 1 of 1

Problems with a file upload script

Posted: Tue May 29, 2007 10:47 am
by aredden
Hey, working on a file upload script, and I have a basic one working fine. I just want to add a bit of security to it so that people I work with dont accidently upload useless files to our server. Here is what I have so far.

But it wont work. And I can't figure out why.


Edited out code due to repost below.

Posted: Tue May 29, 2007 10:50 am
by superdezign
Well, there's no closing bracket...? That could just be the snippet though.

Anyway, when does the problem occur in the code?

Posted: Tue May 29, 2007 10:57 am
by RobertGonzalez
When you say
But it wont work.
what exactly do you mean?

Posted: Tue May 29, 2007 11:12 am
by aredden
Ok, so if i have this i get no error messages. but at the same time I dont think the move_upload_file is working out properly.

Code: Select all

<?php
$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if($_FILES['uploadedfile']['type'] == "text/csv")
{
	if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
	 {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']).  " has been uploaded. ";
    echo ('<a href="main.php" target="_parent">Click Here</a> to enter Fare Quote.');
  }
  else
  {
    echo "There was an error uploading the file, please try again!";
  }
}
?>
this is driving me mad, everything to me looks right remove the if and the ( ) around move_upload_file and get a "Parse error: parse error, unexpected '{' in /home/content/f/m/a/fmafadmin/html/Response/uploader.php on line 17" which i understand because { are for if contatining commands with an if statement. so at the moment im a bit stuck with this. :S

Posted: Tue May 29, 2007 11:21 am
by RobertGonzalez
Show your form please.

On second thought, try this for starters...

Code: Select all

<?php
$target_path = "uploads/";
$target_path .= basename( $_FILES['uploadedfile']['name']); // Why are you doing this?

echo '<-- Upload File Type is ' . $_FILES['uploadedfile']['type'] . ' ... -->';
//if ($_FILES['uploadedfile']['type'] == "text/csv")
//{
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
    {
        echo "The file ".  basename( $_FILES['uploadedfile']['name']).  " has been uploaded. ";
        echo ('<a href="main.php" target="_parent">Click Here</a> to enter Fare Quote.');
    }
    else
    {
        echo "There was an error uploading the file, please try again!";
    }
//}
?>
Then after you run it once to upload the file, view the source to see what the file type. I suspect that the conditional is for some reason evaluating to false so there is no upload.

Posted: Tue May 29, 2007 12:02 pm
by aredden
got it working. but now I have another question im researching. Is it possible to create a file and email it attached to a message all in one script?

if so what am I looking for. a pause or wait function?

Posted: Tue May 29, 2007 12:22 pm
by RobertGonzalez
I would take a look at Swiftmailer written by our very own d11wtq. It has support for mailing attachments. I am sure you could easily integrate the upload with the mailing.

Posted: Tue May 29, 2007 3:13 pm
by aredden
swiftmailer is very very nice:)

i may implement it once I have things up and stable.

for the record mambo leads on to be more than it actually is :S