Problem With files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Problem With files

Post 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?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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']}");
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Post 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')";
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

When PHP throws a parse error notice, the parse error is usually one line above it.
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Post by danharibo »

this line

Code: Select all

$uploadfile = $uploaddir . $_FILES['uploadFile']['name'];
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

What is the exact error text?
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Post by danharibo »

Parse error: parse error in c:\program files\easyphp1-8\www\upload\upload.php on line 9
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Post the first 15 lines of this file --> c:\program files\easyphp1-8\www\upload\upload.php.
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Post 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]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I can't see a parse error in there. But I may just be plain blind right now.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Okay danharibo, next question... have you cleared you browser cache, cookies, etc?
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

That means that there is no array index called 'uploadFile'.
Post Reply