Current location: Hot Scripts Forums » Programming Languages » PHP » Help with my upload script


Help with my upload script

Reply
  #1 (permalink)  
Old 12-04-03, 04:27 PM
TheMetsAreBad TheMetsAreBad is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Help with my upload script

I'm making an upload script and I've completed pretty much everything that I want to do, except for one little thing that I can't figure out how to do. I want to have it so that it won't let people upload files with spaces in them. Can anyone tell me how I would go about doing this?

This is the upload part of the script:

Code:
$dir = "dir";
if ($file != "") {

if (file_exists("$absolute_path/$file_name")) {
die("The file that you have tried to upload already exists.  Please change the name of the file and try uploading again.<br><br><a href=$backhomeurl>Back to Home</a>");
}

if (($sizelimit == "yes") && ($file_size > $sizebytes)) {
die("The file that you have tried to upload is to big. It must be $sizebytes bytes or less.<br><br><a href=$backhomeurl>Back to Home</a>");
}

$ext = strrchr($file_name,'.');
if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
die("The file you are uploading doesn't have an acceptable extension.<br><br>It must have one of the following extensions:<br>$exceptedextension<br><br><a href=$backhomeurl>Back to Home</a>");
}



@copy($file, "$absolute_path/$file_name") or die("The file you are trying to upload couldn't be copied to the server<br><br><a href=$backhomeurl>Back to Home</a>");

} else {
die("Must select file to upload<br><br><a href=$backhomeurl>Back to Home</a>");
}
echo "
<html>
<head>
<title>File Uploaded</title>
</head>
<body>";
echo $file_name." was uploaded";
echo "<br>


<br>The url to your file is:<br><br><b><a href=$dl/$file_name>$dl/$file_name</a></b>
<br><br>
<a href=$PHP_SELF?action=upload>Upload Another File</a>


</body>
</html>";
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 12-04-03, 06:19 PM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
Why not rename the file_name so it doesnt contain spaces.

or use preg_match or preg_match all for "/ /i"
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 12-04-03, 07:10 PM
TheMetsAreBad TheMetsAreBad is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Acecool
Why not rename the file_name so it doesnt contain spaces.
I'm not the person uploading the files, other people are, so I want to set a rule that they can't upload files with spaces.
Quote:
Originally Posted by Acecool
or use preg_match or preg_match all for "/ /i"
That worked...thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
upload script cabj1981 PHP 43 03-04-04 04:19 PM
can never get upload script to wrk... bobby895623 PHP 2 11-26-03 05:14 AM
What to watch when implementing an upload script johno PHP 0 11-21-03 08:00 PM
upload script abbus00 New Members & Introductions 0 07-08-03 06:23 AM
Looking for a script to upload images in a database. boskyvora PHP 2 06-16-03 05:18 AM


All times are GMT -5. The time now is 12:17 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.