Go Back   Computer Forums > Web Design | Website Development > Web Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 04-24-2006, 05:06 PM   #1
Fully Optimized
 
-Paul-'s Avatar
 
Join Date: Jun 2005
Posts: 2,242
Send a message via AIM to -Paul- Send a message via MSN to -Paul-
Default quick php question...

ok so im making an upload script, but i want only .txt files, to be allowed to be uploaded here is my script, what should i add to make it so only .txt files are uploaded...


PHP Code:
<center>
<font size="4">Here you can upload your file it must be in a .txt.  The max size is 50kilobytes.</font>
<br>
<?php
//edit this
$_max_file_size '51200'//file size in bytes.
$upload_dir "uploads/"//upload folder..chmod to 777
//end edit 

echo "Maximum file size : " $_max_file_size/1000 "KB<br>";
echo 
"<form enctype='multipart/form-data' action='?do=upload' method='post'>";
echo 
"<input type='hidden' name='MAX_FILE_SIZE' value='" $_max_file_size "'>";
echo 
"Choose a file to upload: <input name='filename' type='file'>";
echo 
"<input type='submit' value='Upload File'>";
echo 
"</form>";

if(
$_GET['do'] == 'upload')
{
$_random rand(11000000);
$target_path $upload_dir $_random basename($_FILES['filename']['name']); 
$_file_name $_random basename($_FILES['filename']['name']);

if(
move_uploaded_file($_FILES['filename']['tmp_name'], $target_path)) 
{
    echo 
"The file " $_file_name " has been uploaded.";

else
{
    echo 
"There was an error uploading the file, please try again! Maybe be the file size. Maximum file size is " $_max_file_size/1000 "KB";

}
?>
__________________

-Paul- is offline   Reply With Quote
Old 04-25-2006, 02:41 PM   #2
Baseband Member
 
Join Date: Apr 2006
Posts: 50
Send a message via AIM to DanielASanders Send a message via MSN to DanielASanders Send a message via Yahoo to DanielASanders
Default Re: quick php question...

make a simple if statement to check the end of the filename. If it ends with ".txt" then allow the upload.

Code:
if ($filename = substr($filename, -4) == ".txt") {

put rest of upload code here
}
__________________

__________________
I wish I could buy people for what they're worth and sell them for what they think they're worth.
DanielASanders is offline   Reply With Quote
Old 04-25-2006, 05:18 PM   #3
Fully Optimized
 
-Paul-'s Avatar
 
Join Date: Jun 2005
Posts: 2,242
Send a message via AIM to -Paul- Send a message via MSN to -Paul-
Default Re: quick php question...

Quote:
Originally Posted by DanielASanders
make a simple if statement to check the end of the filename. If it ends with ".txt" then allow the upload.

Code:
if ($filename = substr($filename, -4) == ".txt") {

put rest of upload code here
}
can you um put it in up there, i dont know hardly any php...
-Paul- is offline   Reply With Quote
Old 04-27-2006, 07:11 PM   #4
Baseband Member
 
Join Date: Apr 2006
Posts: 50
Send a message via AIM to DanielASanders Send a message via MSN to DanielASanders Send a message via Yahoo to DanielASanders
Default Re: quick php question...

make a simple if statement to check the end of the filename. If it ends with ".txt" then allow the upload.

PHP Code:
if ($filename substr($filename, -4) == ".txt") {

if(
$_GET['do'] == 'upload')
{
$_random rand(11000000);
$target_path $upload_dir $_random basename($_FILES['filename']['name']);
$_file_name $_random basename($_FILES['filename']['name']);

if(
move_uploaded_file($_FILES['filename']['tmp_name'], $target_path))
{
    echo 
"The file " $_file_name " has been uploaded.";
}
else
{
    echo 
"There was an error uploading the file, please try again! Maybe be the file size. Maximum file size is " $_max_file_size/1000 "KB";
}


__________________
I wish I could buy people for what they're worth and sell them for what they think they're worth.
DanielASanders is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 02:58 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0