954,591 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

php uploader script



Choose a file:

slacke
Junior Poster
106 posts since Jun 2006
Reputation Points: 14
Solved Threads: 7
 

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/features.file-upload.errors.php

php_daemon
Junior Poster
140 posts since Aug 2006
Reputation Points: 13
Solved Threads: 2
 

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

And the error output gives nothing :sad:

slacke
Junior Poster
106 posts since Jun 2006
Reputation Points: 14
Solved Threads: 7
 

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??

slacke
Junior Poster
106 posts since Jun 2006
Reputation Points: 14
Solved Threads: 7
 

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.

php_daemon
Junior Poster
140 posts since Aug 2006
Reputation Points: 13
Solved Threads: 2
 

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

slacke
Junior Poster
106 posts since Jun 2006
Reputation Points: 14
Solved Threads: 7
 

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...

slacke
Junior Poster
106 posts since Jun 2006
Reputation Points: 14
Solved Threads: 7
 

What php version do you have installed?

php_daemon
Junior Poster
140 posts since Aug 2006
Reputation Points: 13
Solved Threads: 2
 

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.

slacke
Junior Poster
106 posts since Jun 2006
Reputation Points: 14
Solved Threads: 7
 

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. :)

php_daemon
Junior Poster
140 posts since Aug 2006
Reputation Points: 13
Solved Threads: 2
 

But I included all the modules which was not included. I need now to leav only those modules wich are needed for works like this. ( uploading and downloading files for administration of www directory, and web-cyradm for email administration)


Can you have please a look at it...
I list them:

php5-

bcmath
bz2
calendar
ctype
curl
dba
dbase
devel
dom
exif
fastcgi
filepro
ftp
gd
gettext
gmp
iconv
imap
ldap
mbstring
mcrypt
mhash
mysql
mysqli
ncurses
odbc
openssl
pcntl
pdo
pear
pear-log
pgsql
posix
pspell
shmop
snmp
soap
socket
sqlite
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xmlreader
xmlrpc
xsl
zlib

slacke
Junior Poster
106 posts since Jun 2006
Reputation Points: 14
Solved Threads: 7
 

Actually file uploads is a built-in php feature and no additional extensions are required. At least there's no mentioning of special requirements in php manual.

php_daemon
Junior Poster
140 posts since Aug 2006
Reputation Points: 13
Solved Threads: 2
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You