LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-02-2003, 03:14 AM   #1
kudos
Member
 
Registered: Oct 2002
Location: UK
Distribution: Fedora 4
Posts: 90

Rep: Reputation: 15
Unhappy php upload scipt error


i am having problems with a PHP script to upload files ona http server, when i go 2 upload afile i get this error

Parse error: parse error, unexpected '{' in /website/upload.php on line 14

this happens wit any type of file. trying to upload from my PC to my website.

my html page contains this code
Quote:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<p>FILE Upload Demo page</p>
<form name="form1" method="post" action="upload.php" enctype="multipart/form-data">
<p>File to be uploaded.
<input type="file" name="file">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<p>&nbsp; </p>
</body>
</html>
my php file has this

Quote:
<?php

//Fioe Upload script

$path = "/upload"; //Set this to the full path from ther servers home directory to where the file should be.
//Do not leave a trailing slash.

if($file){

print("File name: $file_name<P>/n");
print("File size: $file_size bytes<P>/n");

if(copy($file, "$path/$file"){

print("Your File was uploaded successfully");
}else{
print("ERROR, your file was not successfully uploaded");
}

unlink($file);
}

?>

could some one please help me out here, many thanks
kudos

Last edited by kudos; 10-02-2003 at 03:16 AM.
 
Old 10-02-2003, 03:30 AM   #2
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
Well if this, " if(copy($file, "$path/$file"){" is line 14. I think you should change it to:

if(copy($file, "$path/$file")){
 
Old 10-02-2003, 03:36 AM   #3
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
Also This part:
Code:
print("File name: $file_name<P>/n");
print("File size: $file_size bytes<P>/n");
Should be:
Code:
$file_size = filesize($file);
print("File name: $file<P>/n");
print("File size: $file_size bytes<P>/n");
But I don't know if this will solve you problems. Just what I see.
 
Old 10-02-2003, 04:16 AM   #4
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
Well I coulnd not get you script to work. So Here's a better way:

Code:
<?php
$uploaddir = '/usr/local/httpd/htdocs/uploads/';
$uploadfile = $uploaddir. $_FILES['file']['name'];
print "<pre>";
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
    print "File is valid, and was successfully uploaded. ";
    print "Here's some more debugging info:\n";
    print_r($_FILES);
} else {
    print "Possible file upload attack!  Here's some debugging info:\n";
    print_r($_FILES);
}
print "</pre>";
exit;
?>
 
Old 10-02-2003, 05:01 AM   #5
kudos
Member
 
Registered: Oct 2002
Location: UK
Distribution: Fedora 4
Posts: 90

Original Poster
Rep: Reputation: 15
HI tx for the replys every one

micxz u was right i could't get it to work ether, but ur script works grate, many thx for that

thx
kudos
 
Old 10-02-2003, 05:32 AM   #6
kudos
Member
 
Registered: Oct 2002
Location: UK
Distribution: Fedora 4
Posts: 90

Original Poster
Rep: Reputation: 15
HI

just tryed 2 upload a 14mb file to the server and i get
Possible file upload attack! Here's some debugging info:
Array
(
)

same ither anythink bigger than a 14mb file eg 500mb

i can upload 3mb ok

i have
upload_max_filesize 900M

do i need to edit any other config settings?

many thanks kudos
 
Old 10-02-2003, 07:48 AM   #7
nephilim
Member
 
Registered: Aug 2003
Location: Belgium
Distribution: Debian (server), Kubuntu (desktop)
Posts: 248

Rep: Reputation: 30
What is the setting of max_file_size in php.ini? Maybe you should change that.
 
Old 10-02-2003, 07:53 AM   #8
nephilim
Member
 
Registered: Aug 2003
Location: Belgium
Distribution: Debian (server), Kubuntu (desktop)
Posts: 248

Rep: Reputation: 30
Also, if your method=post, you should probably change post_max_size as well.
 
Old 10-02-2003, 01:59 PM   #9
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
You can add a hidden field to the form like:

<input type="hidden" name="MAX_FILE_SIZE" value="999999999999">

But I don't beleive this will override the php.ini

Last edited by micxz; 10-02-2003 at 02:04 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Php Upload Files rabee77 Linux - Software 1 01-16-2005 05:26 AM
upload dir with php retrodict Programming 0 12-08-2004 02:52 AM
How to exec a comman from mnt/ drive in php scipt osward Programming 5 04-04-2004 03:47 AM
ftp upload in php raven Programming 2 07-07-2002 05:33 PM
File upload via PHP saravanan1979 Programming 1 02-14-2002 04:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration