Check my script?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
monkeyj
Forum Commoner
Posts: 82
Joined: Mon Dec 15, 2003 4:32 pm
Location: USA
Contact:

Check my script?

Post by monkeyj »

I'm trying to make a UPLOAD to FTP script through a form..
I don't know if I quite got it right or not..
I have the HTML form.. with..

Code: Select all

<form enctype="multipart/form-data" action="/anims/submit.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1572864">
Send this file: <input name="userfile" type="file">
<input type="submit" value="Send File">
</form>
and in the PHP file I have...

Code: Select all

<?php 
if (is_uploaded_file($_FILES&#1111;'userfile']&#1111;'tmp_name'])) &#123;
    copy($_FILES&#1111;'userfile']&#1111;'tmp_name'], "/anims/upload");
&#125; else &#123;
    echo "Possible file upload attack. Filename: " . $_FILES&#1111;'userfile']&#1111;'name'];
&#125;
/* ...or... */
move_uploaded_file($_FILES&#1111;'userfile']&#1111;'tmp_name'], "/anims/upload");
?>
Am I doing somethign wrong?

Help?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

What are the errors?
User avatar
monkeyj
Forum Commoner
Posts: 82
Joined: Mon Dec 15, 2003 4:32 pm
Location: USA
Contact:

o.o none

Post by monkeyj »

There is no error..
It wants me to download the PHP file..
both the submit.html and submit.php are on my desktop
and I have a folder called "anims" with "upload" in it..

the codes are:

HTML:

Code: Select all

<form enctype="multipart/form-data" action="submit.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1572864">
Send this file: <input name="userfile" type="file">
<input type="submit" value="Send File">
</form>
PHP:

Code: Select all

<?php 
if (is_uploaded_file($_FILES&#1111;'userfile']&#1111;'tmp_name'])) &#123;
    copy($_FILES&#1111;'userfile']&#1111;'tmp_name'], "/anims/upload");
&#125; else &#123;
    echo "Possible file upload attack. Filename: " . $_FILES&#1111;'userfile']&#1111;'name'];
&#125;
/* ...or... */
move_uploaded_file($_FILES&#1111;'userfile']&#1111;'tmp_name'], "/anims/upload");
?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Might be a stupid question but.. your running this on a server right?
both the submit.html and submit.php are on my desktop
User avatar
monkeyj
Forum Commoner
Posts: 82
Joined: Mon Dec 15, 2003 4:32 pm
Location: USA
Contact:

Post by monkeyj »

My bad, meant server.. and.. Yes I am..

And I tried it again.. and did get an error this time..

Warning: copy(/anims/upload): failed to open stream: No such file or directory in /home/hsphere/local/home/monkeyj/monkeyblast.com/submit.php on line 4

Warning: move_uploaded_file(/anims/upload): failed to open stream: No such file or directory in /home/hsphere/local/home/monkeyj/monkeyblast.com/submit.php on line 9

Warning: move_uploaded_file(): Unable to move '/tmp/phptRS7lX' to '/anims/upload' in /home/hsphere/local/home/monkeyj/monkeyblast.com/submit.php on line 9
User avatar
monkeyj
Forum Commoner
Posts: 82
Joined: Mon Dec 15, 2003 4:32 pm
Location: USA
Contact:

new code

Post by monkeyj »

Just to make sure we have the same code...

Code: Select all

<?php 
if (is_uploaded_file($_FILES&#1111;'userfile']&#1111;'tmp_name'])) &#123; 
    copy($_FILES&#1111;'userfile']&#1111;'tmp_name'], "/anims/upload"); 
&#125; else &#123; 
    echo "Possible file upload attack. Filename: " . $_FILES&#1111;'userfile']&#1111;'name']; 
&#125; 
/* ...or... */ 
move_uploaded_file($_FILES&#1111;'userfile']&#1111;'tmp_name'], "/anims/upload"); 
?>


ERROR:
Warning: copy(/anims/upload): failed to open stream: No such file or directory in /home/hsphere/local/home/monkeyj/monkeyblast.com/submit.php on line 3

Warning: move_uploaded_file(/anims/upload): failed to open stream: No such file or directory in /home/hsphere/local/home/monkeyj/monkeyblast.com/submit.php on line 8

Warning: move_uploaded_file(): Unable to move '/tmp/phpxgYcdl' to '/anims/upload' in /home/hsphere/local/home/monkeyj/monkeyblast.com/submit.php on line 8
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

"/anims/upload/" this directory exists right?

Also make sure you have set the permissions correctly

the directory should be http://localhost/monkeyj/anims/upload
User avatar
monkeyj
Forum Commoner
Posts: 82
Joined: Mon Dec 15, 2003 4:32 pm
Location: USA
Contact:

Post by monkeyj »

I wouldn't need the slash at the end would I?

but.. anims/upload does exist...

Which permissions?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

umm most likely you will need it..

CHMOD the permissions... should be set to 777 i believe
User avatar
monkeyj
Forum Commoner
Posts: 82
Joined: Mon Dec 15, 2003 4:32 pm
Location: USA
Contact:

Post by monkeyj »

Put the slash.. It doesnt matter :P but.. yes.. anims/upload is up
User avatar
monkeyj
Forum Commoner
Posts: 82
Joined: Mon Dec 15, 2003 4:32 pm
Location: USA
Contact:

Post by monkeyj »

I can't find the permissions...
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

gimme a few min ima go and run this on my server
User avatar
monkeyj
Forum Commoner
Posts: 82
Joined: Mon Dec 15, 2003 4:32 pm
Location: USA
Contact:

Post by monkeyj »

k
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

BTW might want to blank out your directory..

instead of /home/domain/folder do like /home/****/folder
User avatar
monkeyj
Forum Commoner
Posts: 82
Joined: Mon Dec 15, 2003 4:32 pm
Location: USA
Contact:

Post by monkeyj »

:-/ well I got two domains running from one host..
and thats the way the host set it up...

and I'm not too smart when it comes to deleting stuff alrdy set up :P
Post Reply