•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,661 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,820 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2332 | Replies: 11 | Solved
![]() |
•
•
Join Date: Jun 2006
Location: Slovakia, Bratislava
Posts: 63
Reputation:
Rep Power: 3
Solved Threads: 1
I want to create a simple script for uploading files from local maschine (windows) to a web servers (linux) directory.
I found on the net some example codes and make the two parts of that simple script.
1. The HTML form creation...
[php]
<html>
<body>
<form enctype="multipart/from-data" action="upload.php" method="POST">
Choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>
</body>
</html>
[/php]
2. ...which calls the upload.php script
[php]
<?php
$target='/srv/www/htdocs/www/';
$target= $target . basename($_FILES['uploaded']['name']);
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "File". basename($_FILES['uploadedfile']
['name']). "uploaded succesfully";
}
else
{
echo "An error occured";
}
?>
[/php]
I get "An error occured" message while trying to upload something.
I might have also problems with the file permission in linux.
I create a ./upload/ directory in the www root and I don't exactly know who should be the owner of that directory and in what group it should be. I tried the user and group wich is udsed for apache.
Can anyone help please?
I found on the net some example codes and make the two parts of that simple script.
1. The HTML form creation...
[php]
<html>
<body>
<form enctype="multipart/from-data" action="upload.php" method="POST">
Choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>
</body>
</html>
[/php]
2. ...which calls the upload.php script
[php]
<?php
$target='/srv/www/htdocs/www/';
$target= $target . basename($_FILES['uploaded']['name']);
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "File". basename($_FILES['uploadedfile']
['name']). "uploaded succesfully";
}
else
{
echo "An error occured";
}
?>
[/php]
I get "An error occured" message while trying to upload something.
I might have also problems with the file permission in linux.
I create a ./upload/ directory in the www root and I don't exactly know who should be the owner of that directory and in what group it should be. I tried the user and group wich is udsed for apache.
Can anyone help please?
Last edited by slacke : Jan 30th, 2007 at 4:04 am.
•
•
Join Date: Aug 2006
Posts: 138
Reputation:
Rep Power: 3
Solved Threads: 2
The owner of the directory should be php, not apache.
Also:
[php]
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "File". basename($_FILES['uploadedfile']
['name']). "uploaded succesfully";
}
else
{
echo "An error occured. Error code: ".$_FILES['uploadedfile']['error'];
}
[/php]
And check the code against http://www.php.net/manual/en/feature...oad.errors.php
Also:
[php]
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "File". basename($_FILES['uploadedfile']
['name']). "uploaded succesfully";
}
else
{
echo "An error occured. Error code: ".$_FILES['uploadedfile']['error'];
}
[/php]
And check the code against http://www.php.net/manual/en/feature...oad.errors.php
•
•
Join Date: Jun 2006
Location: Slovakia, Bratislava
Posts: 63
Reputation:
Rep Power: 3
Solved Threads: 1
•
•
Join Date: Jun 2006
Location: Slovakia, Bratislava
Posts: 63
Reputation:
Rep Power: 3
Solved Threads: 1
•
•
Join Date: Aug 2006
Posts: 138
Reputation:
Rep Power: 3
Solved Threads: 2
Really seems to be the permissions. There should be a user for php (it's not named php) but php runs under some user name (sorry for not being specific, I'm not a *nix guru).
Well, if you can't get it going, set the permissions to 0777 then. It's not very secure, but you can move the upload directory out from the web server root, so it's not accessible in public, to improve the security.
Well, if you can't get it going, set the permissions to 0777 then. It's not very secure, but you can move the upload directory out from the web server root, so it's not accessible in public, to improve the security.
•
•
Join Date: Jun 2006
Location: Slovakia, Bratislava
Posts: 63
Reputation:
Rep Power: 3
Solved Threads: 1
•
•
Join Date: Jun 2006
Location: Slovakia, Bratislava
Posts: 63
Reputation:
Rep Power: 3
Solved Threads: 1
I have find some error-logs wich tells:
error: PHP Notice: Undefined index: uploaded in /srv/www/htdocs/www/upload.php on line 3 referer: http://www.mydomain.com/
and same in the line 4, 10
it seems like it dose not know these variables...
error: PHP Notice: Undefined index: uploaded in /srv/www/htdocs/www/upload.php on line 3 referer: http://www.mydomain.com/
and same in the line 4, 10
it seems like it dose not know these variables...
•
•
Join Date: Jun 2006
Location: Slovakia, Bratislava
Posts: 63
Reputation:
Rep Power: 3
Solved Threads: 1
I use php version 5.1.2-29.5.
I made several tests. I checked the php modules and I found out I did not include several modules. I think the most important was the ctype Extension module.
choose a litle drastic method and checked all extension modules to be included.
But I dont know which ones are needed.
the uploading starts to work after I found an another script on the net whith one more function in it.
[php]
is_uploaded_file($_FILES['upload']['tmp_file'])
[/php]
after this function the move_uploaded_file(...) starts to work.
I made several tests. I checked the php modules and I found out I did not include several modules. I think the most important was the ctype Extension module.
choose a litle drastic method and checked all extension modules to be included.
But I dont know which ones are needed.
the uploading starts to work after I found an another script on the net whith one more function in it.
[php]
is_uploaded_file($_FILES['upload']['tmp_file'])
[/php]
after this function the move_uploaded_file(...) starts to work.
Last edited by slacke : Feb 1st, 2007 at 12:17 pm.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
Other Threads in the PHP Forum
- Previous Thread: php photo click counter
- Next Thread: Variable typing in PHP?


Linear Mode