944,098 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 3696
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Jan 30th, 2007
0

php uploader script

Expand Post »
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?
Last edited by slacke; Jan 30th, 2007 at 5:04 am.
Similar Threads
Reputation Points: 14
Solved Threads: 7
Junior Poster
slacke is offline Offline
105 posts
since Jun 2006
Jan 30th, 2007
0

Re: php uploader script

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
Reputation Points: 13
Solved Threads: 2
Junior Poster
php_daemon is offline Offline
138 posts
since Aug 2006
Jan 30th, 2007
0

Re: php uploader script

I have not such a user (php). (its SuSE Enter.serv. 10 distro).

And the error output gives nothing
Last edited by slacke; Jan 30th, 2007 at 6:12 am.
Reputation Points: 14
Solved Threads: 7
Junior Poster
slacke is offline Offline
105 posts
since Jun 2006
Jan 30th, 2007
0

Re: php uploader script

I cache the tcp stream when trying the uplod script and in the tcp stream is shown that the uploaded=C%3A%5Ctext.txt

Where the text.txt file is on the local disk C:/

But it seems to mee that there is something wrong with uploaded??
Last edited by slacke; Jan 30th, 2007 at 7:39 am.
Reputation Points: 14
Solved Threads: 7
Junior Poster
slacke is offline Offline
105 posts
since Jun 2006
Jan 30th, 2007
0

Re: php uploader script

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.
Reputation Points: 13
Solved Threads: 2
Junior Poster
php_daemon is offline Offline
138 posts
since Aug 2006
Jan 30th, 2007
0

Re: php uploader script

I am going to check the php.ini maybe it will be there. ( or somewhere in the apache confs)

I think in linux the user will be the wwwrun which is for apache and apache uses php as modul - so php will be probably the same ( not sure about it).

I am going to thread in linux forums.
Thanks
Reputation Points: 14
Solved Threads: 7
Junior Poster
slacke is offline Offline
105 posts
since Jun 2006
Jan 30th, 2007
0

Re: php uploader script

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...
Reputation Points: 14
Solved Threads: 7
Junior Poster
slacke is offline Offline
105 posts
since Jun 2006
Jan 30th, 2007
0

Re: php uploader script

What php version do you have installed?
Reputation Points: 13
Solved Threads: 2
Junior Poster
php_daemon is offline Offline
138 posts
since Aug 2006
Feb 1st, 2007
0

Re: php uploader script

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.
Last edited by slacke; Feb 1st, 2007 at 1:17 pm.
Reputation Points: 14
Solved Threads: 7
Junior Poster
slacke is offline Offline
105 posts
since Jun 2006
Feb 1st, 2007
0

Re: php uploader script

It seems strange that is_uploaded_file changes anything, it only tells whether the file was uploaded. I'll keep that in mind for future reference. Glad you worked it out.
Reputation Points: 13
Solved Threads: 2
Junior Poster
php_daemon is offline Offline
138 posts
since Aug 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: php photo click counter
Next Thread in PHP Forum Timeline: Variable typing in PHP?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC