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
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
10-02-2003, 03:14 AM
#1
Member
Registered: Oct 2002
Location: UK
Distribution: Fedora 4
Posts: 90
Rep:
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> </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 .
10-02-2003, 03:30 AM
#2
Senior Member
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131
Rep:
Well if this, " if(copy($file, "$path/$file"){" is line 14. I think you should change it to:
if(copy($file, "$path/$file")){
10-02-2003, 03:36 AM
#3
Senior Member
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131
Rep:
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.
10-02-2003, 04:16 AM
#4
Senior Member
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131
Rep:
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;
?>
10-02-2003, 05:01 AM
#5
Member
Registered: Oct 2002
Location: UK
Distribution: Fedora 4
Posts: 90
Original Poster
Rep:
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
10-02-2003, 05:32 AM
#6
Member
Registered: Oct 2002
Location: UK
Distribution: Fedora 4
Posts: 90
Original Poster
Rep:
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
10-02-2003, 07:48 AM
#7
Member
Registered: Aug 2003
Location: Belgium
Distribution: Debian (server), Kubuntu (desktop)
Posts: 248
Rep:
What is the setting of max_file_size in php.ini? Maybe you should change that.
10-02-2003, 07:53 AM
#8
Member
Registered: Aug 2003
Location: Belgium
Distribution: Debian (server), Kubuntu (desktop)
Posts: 248
Rep:
Also, if your method=post, you should probably change post_max_size as well.
10-02-2003, 01:59 PM
#9
Senior Member
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131
Rep:
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 .
All times are GMT -5. The time now is 03:01 PM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News