PHP Help

- General Comments.

Moderators: Voice Dax, Voice Aeneas

PHP Help

Postby Atticus Forghon » Wed Jul 22, 2009 4:37 pm

Ok I got this file upload script from about.com here http://php.about.com/od/advancedphp/ss/ ... upload.htm and it works for the most part. However, the size limitation and file extension limitation do not work. I had it set up where when entering the download area, the user was required to enter a password and username to continue. Once entered correctly, a page came up allowing the user to upload a file. It works fine and the files upload successfully. Everything was good and I was very happy. I then decided to try to upload a file larger than the allowed limit and then another file with an extension that is not allowed. Both uploaded just fine. I can't figure out why these limitations are not working and obviously I can't make this feature available on the site yet cause people could accidently upload extremely large files or even .exe files or other potentially harmful files. Any help would be greatly appreciated!!! :D
Atticus
Dark Fellowship
§otEP Forever
User avatar
Atticus Forghon
Stablehand
 
Posts: 401
Joined: Sun Oct 06, 2002 5:21 pm
Location: Missouri, USA

Re: PHP Help

Postby I]\/[mortality » Wed Jul 22, 2009 6:02 pm

if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}

where does $uploaded_size come from? i dont see it set anywhere (though that prolly have to do with global variables or soemthing related to php)

i would suggest using $_FILES["file"]["size"] and $_FILES["file"]["type"]

http://www.w3schools.com/PHP/php_file_upload.asp
Retired
User avatar
I]\/[mortality
Journeyman
 
Posts: 2532
Joined: Wed Sep 17, 2003 11:35 pm
Location: Toronto, Canada

Re: PHP Help

Postby Atticus Forghon » Wed Jul 22, 2009 6:17 pm

The variable uploaded comes from the html form where the file is submitted. But I will take a look at what you suggested and see if I cant get it working that way.
Atticus
Dark Fellowship
§otEP Forever
User avatar
Atticus Forghon
Stablehand
 
Posts: 401
Joined: Sun Oct 06, 2002 5:21 pm
Location: Missouri, USA

Re: PHP Help

Postby zenpig » Wed Jul 22, 2009 11:09 pm

I went hunting for a script I used a couple of years ago which from how you previously described your project I thought would work for you but sorry, no joy...couldn't find it. But, a few that are free pre-written user login scripts for uploading files that I came across are at http://new.bkworksproducts.info/?view=v ... ilemanager and
http://www.maianscriptworld.co.uk/free- ... index.html

If you can use something like the above instead of trying to reinvent the wheel(these also are a bit more robust)it would probably save you a lot of time and headache.
"The trouble with socialism is that you eventually run out of other people's money" ~M. Thatcher

If I could buy my reasoning I pay to lose
User avatar
zenpig
Journeyman
 
Posts: 2220
Joined: Wed Sep 25, 2002 5:00 pm

Re: PHP Help

Postby Crnogorac » Mon Jul 19, 2010 10:36 am

They forgot two variables:
$uploaded_size = $_FILES['uploaded']['size'];
$uploaded_type = $_FILES["uploaded"]["type"];

Here, instead
basename( $_FILES['uploadedfile']['name']).
there must be
basename( $_FILES['uploaded']['name']).
.


Thus should look like functional code that works
Code: Select all
<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$uploaded_size = $_FILES['uploaded']['size'];
$uploaded_type = $_FILES["uploaded"]["type"];
$ok=1;
//This is our size condition
if ($uploaded_size > 350000) {
echo "Your file is too large.<br>";
$ok=0;
}

//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']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } } ?>


Sorry for bad English :wink:
Crnogorac
Stablehand
 
Posts: 1
Joined: Mon Jul 19, 2010 10:27 am


Return to Comments

Who is online

Users browsing this forum: No registered users

cron