
September 21st, 2003
09:03 PM
PHP upload
I recently used the tutorial on this page http://robouk.mchost.com/tuts/tutorial.php?tutorial=fileupload
when I had a WinXP server. I found it easy and effective but windows was limiting me because i couldn't set file permissions. So i decided to Install linux, and by golly, It's Fantastic. I got FTP, Apache, Samba, DNS, SMTP, IMAP, POP3 and Webmail all up and working. And now I can set file permissions, and the upload script from the tutorial works now. However there is one restriction i would like to know how to add. This upload tutorial doesn't limit what file type to upload. I would like to be able to only let .ZIP files 1MB or less to be uploaded. CAn anybody point me in the right direction?? or tell me how to add this funciton to the php script?
thanks
Michael
___________________


September 21st, 2003
11:10 PM
just check the file name
<?php
$tmp_name = $_FILES['userfile']['tmp_name'];
if(substr($tmp_name, -3) == "zip"){
// execute code...
}
?>
something like that worked for me...

September 22nd, 2003
12:13 AM
16, staying Asian.
Status: Offline!
it's better if you check the mime type cause i can just rename the file to have .zip
<?php
if($_FILES['userfile']['type'] != "application/zip") {
echo "this ain't no zip";
} else {
// upload code
}
?>
___________________


September 22nd, 2003
12:33 AM
Neverside Newbie
Status: Offline!
Nice error message, ep, I like it.
___________________
Travis Farrell


September 22nd, 2003
12:47 AM
true. good call. I'm used to working for morons that don't know how to rename files so that never really was a problem. 

September 22nd, 2003
06:26 PM
hrm.
I tried to add that code you said and heres what i have.
<?php
if($_FILES['userfile']['type'] != "application/zip") {
echo "this ain't no zip";
} else {
if(!(copy($_FILES['userfile']['tmp_name'], "uploads/" . $_FILES['userfile']['name']))) die("Cannot upload files.");
echo "Upload Complete!";
}
?>
now even if i try to upload a zip file, it says "this ain't no zip!"
any help?
___________________


September 22nd, 2003
06:56 PM
Hey is there anyway you could extend on this and tell us how to make a page that will show the most recent uploads or somthing im kind of a noob
___________________
// RANKING = n00b \\

September 22nd, 2003
07:04 PM
Neverside Newbie
Status: Offline!
Yep... it's called a search.
___________________
Travis Farrell


September 22nd, 2003
07:06 PM
no i want like a page to post the most recent uploads that have been uploaded..... And if possible on the main page.
___________________
// RANKING = n00b \\

September 22nd, 2003
07:08 PM
*cough*
can we get back to why my code isn't working?? 
thanks
___________________
