Page 1 of 2

Problem With files

Posted: Tue Sep 19, 2006 1:40 pm
by danharibo
I have an upload script, but php is ginving me a prase error at the marked line:

Code: Select all

<?php
include('database.php');
$uploaddir = 'uploads/';
move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
       "../uploads/{$_FILES['uploadFile'] ['name']}")

//print("File (Probably) uploaded, it will now be Added to the database.");
$uploadfile = $uploaddir . basename($_FILES['uploadFile']['name']); // THIS LINE <<<
//Insert into db
$sql = "INSERT INTO ez_downloads (name,timestamp,description,submit_by,filename) VALUES ('test','2','Test-download','bob123','$uploadedfile')";

    $result = mysql_query($sql) or print("Can't upload and store file, please ask an admin for help.<br />" . $sql . "<br />" . mysql_error());

?>
What is wrong with it?

Posted: Tue Sep 19, 2006 2:02 pm
by RobertGonzalez
You're missing a semicolon at the end of this line:

Code: Select all

move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
       "../uploads/{$_FILES['uploadFile'] ['name']}")
You may want to change it too this...

Code: Select all

move_uploaded_file($_FILES['uploadFile']['tmp_name'], "../uploads/{$_FILES['uploadFile']['name']}");

Posted: Wed Sep 20, 2006 12:02 pm
by danharibo
Now i get a parse error on this line :/

Code: Select all

$sql = "INSERT INTO ez_downloads (name,timestamp,description,submit_by,filename) VALUES ('test','2','Test-download','bob123','$uploadedfile')";

Posted: Wed Sep 20, 2006 1:06 pm
by volka
Now i get a parse error on this line :/
a secret parse error?

Code: Select all

<?php
$sql = "INSERT INTO ez_downloads (name,timestamp,description,submit_by,filename) VALUES ('test','2','Test-download','bob123','$uploadedfile')";
?>
No syntax errors detected in /home/volker/phpdn/test.php
The error is caused before that line of code.

Posted: Wed Sep 20, 2006 1:24 pm
by RobertGonzalez
When PHP throws a parse error notice, the parse error is usually one line above it.

Posted: Wed Sep 20, 2006 1:44 pm
by danharibo
this line

Code: Select all

$uploadfile = $uploaddir . $_FILES['uploadFile']['name'];

Posted: Wed Sep 20, 2006 1:46 pm
by RobertGonzalez
What is the exact error text?

Posted: Wed Sep 20, 2006 1:48 pm
by danharibo
Parse error: parse error in c:\program files\easyphp1-8\www\upload\upload.php on line 9

Posted: Wed Sep 20, 2006 1:51 pm
by RobertGonzalez
Post the first 15 lines of this file --> c:\program files\easyphp1-8\www\upload\upload.php.

Posted: Wed Sep 20, 2006 1:54 pm
by danharibo
Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

<?php
include('database.php');
$uploaddir = 'uploads/';
move_uploaded_file($_FILES['uploadFile']['tmp_name'], "../uploads/{$_FILES['uploadFile']['name']}");

//print("File (Probably) uploaded, it will now be Added to the database.");
$uploadfile = $uploaddir . $_FILES['uploadFile']['name'];
//Insert into db
$sql = "INSERT INTO ez_downloads (name,timestamp,description,submit_by,filename) VALUES ('test','2','Test-download','bob123','$uploadedfile')";

    $result = mysql_query($sql) or print("Can't upload and store file, please ask an admin for help.<br />" . $sql . "<br />" . mysql_error());

?>

Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Sep 20, 2006 2:09 pm
by RobertGonzalez
I can't see a parse error in there. But I may just be plain blind right now.

Posted: Wed Sep 20, 2006 2:15 pm
by volka
I can't see a parse error in there. But I may just be plain blind right now.
php -l as well ;)
<?php
include('database.php');
$uploaddir = 'uploads/';
move_uploaded_file($_FILES['uploadFile']['tmp_name'], "../uploads/{$_FILES['uploadFile']['name']}");

//print("File (Probably) uploaded, it will now be Added to the database.");
$uploadfile = $uploaddir . $_FILES['uploadFile']['name'];
//Insert into db
$sql = "INSERT INTO ez_downloads (name,timestamp,description,submit_by,filename) VALUES ('test','2','Test-download','bob123','$uploadedfile')";

$result = mysql_query($sql) or print("Can't upload and store file, please ask an admin for help.<br />" . $sql . "<br />" . mysql_error());

?>
No syntax errors detected in /home/volker/phpdn/test.php

Posted: Wed Sep 20, 2006 2:20 pm
by RobertGonzalez
Okay danharibo, next question... have you cleared you browser cache, cookies, etc?

Posted: Thu Sep 21, 2006 9:51 am
by danharibo
ok, now i'm getting this
Notice: Undefined index: uploadFile in c:\program files\easyphp1-8\www\upload\upload.php on line 4

Notice: Undefined index: uploadFile in c:\program files\easyphp1-8\www\upload\upload.php on line 4

Notice: Undefined index: uploadFile in c:\program files\easyphp1-8\www\upload\upload.php on line 7

Notice: Undefined variable: uploadedfile in c:\program files\easyphp1-8\www\upload\upload.php on line 9

Posted: Thu Sep 21, 2006 10:07 am
by RobertGonzalez
That means that there is no array index called 'uploadFile'.