inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Sept 15, 2009 14:13:21 GMT -8
This is what I get when I try to upload something to my website, via a PHP script I found.. Warning: basename() expects parameter 1 to be string, array given in /home/a8848808/public_html/upload.php on line 3 Here is the link if it would be needed.. erinuki.hostoi.com/upload.htmlI am using this code for the upload.php part: <?php $target = "upload/"; $target = $target . basename( $_FILES['uploaded']) ; $ok=1;
//This is our limit file type condition if ($uploaded_type =="text/php") { echo "No PHP files<br>"; $ok=0; }
//Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded."; }
//If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file. Please try again."; } } ?>
I have that in the file labeled upload.php in my public_html/ folder.. along with the upload.html. I have the "upload" directory created.. what is going wrong? Help!!
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Sept 15, 2009 18:14:05 GMT -8
Exactly what the error says.echo "The file ". basename( $_FILES['uploadedfile']). " has been uploaded"; $_FILES['uploadedfile'] is an Array. basename only accepts strings.
echo "The file ", htmlentities($_FILES["uploadedfile"]["name"]), " has been uploaded";
|
|
inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Sept 16, 2009 5:33:06 GMT -8
Sweet! Thanks Charles! I know nothing about PHP, that is why i asked here xD THanks again
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Sept 16, 2009 13:16:54 GMT -8
For future reference, just pay attention to what it says after "Warning:" or whatever it says. PHP tells you how to debug the code in its errors. If it gives a function name, look in your code for where that function is used (usually, it'll tell what line number and such). Find what it says is wrong with the function (e.g. Array given, string expected). If you don't know what the error specifically means, just take the key words (Array, string) and check the PHP manual (http://php.net/basename) for proper usage. Good luck in future projects.
|
|
inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Sept 16, 2009 15:31:29 GMT -8
So.. what should the code be for the upload.php part? and is the HTML part right?
|
|
inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Sept 19, 2009 18:26:55 GMT -8
Would it be like: <?php $target = "upload/"; $target = $target . basename( $_FILES['uploaded']) ; $ok=1;
//This is our limit file type condition if ($uploaded_type =="text/php") { echo "No PHP files<br>"; $ok=0; }
//Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded."; }
//If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded'], $target)) { echo "The file ", htmlentities($_FILES["uploadedfile"]["name"]), " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file. Please try again."; } } ?>
|
|
inherit
12045
0
Nov 19, 2012 14:52:05 GMT -8
Renegade
As unique as mice pudding milkshake
40,557
August 2003
renegade
|
Post by Renegade on Sept 19, 2009 18:56:43 GMT -8
just one quick note - if tha'ts going to be public, liek the link currently is for it, you're going to need a bit more security than that
|
|
inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Sept 20, 2009 6:44:02 GMT -8
I know that.. but this is just simple so that i can upload stuff to the server without having to login to the FTP account.. so if someone wants to make a more complex code, go ahead.
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Sept 20, 2009 8:27:05 GMT -8
Well, for one, $uploaded_type is never set anywhere. So that would make it an empty string. So when you compare $uploaded_type to "text/php," it will always return false (even for a PHP file), since you're not setting it. Also, by more security, I think he means the types of files that are allowed. Instead of saying, "if it's not PHP," you should be saying, "If it is[/b] JPG, GIF, PNG, other-files-you-want-allowed," as there are more malicious files than PHP.
|
|
inherit
12045
0
Nov 19, 2012 14:52:05 GMT -8
Renegade
As unique as mice pudding milkshake
40,557
August 2003
renegade
|
Post by Renegade on Sept 20, 2009 11:17:21 GMT -8
If it's only for you to upload with, and nobody else will ever access the upladoer, then it doesn't matter. but then you'd need to password protect the page or something just to make sure of that I actualyl can't think of anything more malicious to uplad to a web server than a PHP file, since if tyou can do that, you haev complete control over the server from that point. trust me, i've done that before however, even if you were checking what was being uplaoded, you need to disallow more than just PHP, or at least double check that your host isn't going to overwrite fiels that are uploaded like that. Someof them will do, never ever assume that if I try to uplaod a new htaccess file (which would allow me to bypass the php file uploading restriction), your host wil lautomatically refuse it There's more than that to think about though The other problem with it is that even if you disallow script fiels to be uploaded, there's nothing stoppin me backin up my hard drive and uploading half a terabyte of data to your host. that would use ALL your bandwidth, and then some, and probably get you suspended and fined by your webhost
|
|
inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Sept 20, 2009 13:51:39 GMT -8
Than what should I do? What codes should I use? This isn't really helping me..
|
|
inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Sept 21, 2009 14:59:42 GMT -8
BUMP!! This still needs help.
|
|
inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Oct 1, 2009 17:29:18 GMT -8
BUMP! Still needs help..
|
|