![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Too lazy to set a custom title
Industry Role:
Join Date: May 2003
Location: icq: 71462500 Skype: Jupzchris
Posts: 27,880
|
php gurus question inside
I have an upload script
Code:
<?php // Where the file is going to be placed $target_path = "uploads/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $_FILES['uploadedfile']['tmp_name']; $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> i want it to remove the spaces in the file name when uploaded quick fix?????? also anytime i upload a file over like 1 meg i get There was an error uploading the file, please try again! i know what the issue is ... but i increase the size but i think im doing it right Code:
<html> <form enctype="multipart/form-data" action="uploader.php" method=hahahahahaha> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> </html> what value would I put for like max 200megs
__________________
[email protected] |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
<&(©¿©)&>
Industry Role:
Join Date: Jul 2002
Location: Chicago
Posts: 47,882
|
you need to change the setting via php.ini or .htaccess to increase the limit over 1 meg...
__________________
Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000 Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager ![]() Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 | |
Too lazy to set a custom title
Industry Role:
Join Date: May 2003
Location: icq: 71462500 Skype: Jupzchris
Posts: 27,880
|
Quote:
default server is liek 1 meg or something?
__________________
[email protected] |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
<&(©¿©)&>
Industry Role:
Join Date: Jul 2002
Location: Chicago
Posts: 47,882
|
create a phpinfo.php file and put <?php phpinfo(); ?> in it, it will tell you bunch of stuff about php, including your current upload file size limit...
__________________
Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000 Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager ![]() Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Too lazy to set a custom title
Industry Role:
Join Date: May 2003
Location: icq: 71462500 Skype: Jupzchris
Posts: 27,880
|
damn woj you a gangsta
sho nuff max upload 2 megs now time to break my server and edit that lol
__________________
[email protected] |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
<&(©¿©)&>
Industry Role:
Join Date: Jul 2002
Location: Chicago
Posts: 47,882
|
and on a sidenote, be careful with a script like that, what you have there is not very secure, some loser can upload some script instead of a pic, letting him do whatever he wants on your server
__________________
Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000 Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager ![]() Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 | |
Too lazy to set a custom title
Industry Role:
Join Date: May 2004
Location: West Coast, Canada.
Posts: 10,217
|
Quote:
Code:
$filename=preg_replace("/\s+/g","",$filename); |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 | |
Too lazy to set a custom title
Industry Role:
Join Date: May 2003
Location: icq: 71462500 Skype: Jupzchris
Posts: 27,880
|
Quote:
![]()
__________________
[email protected] |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 | |
Too lazy to set a custom title
Industry Role:
Join Date: May 2003
Location: icq: 71462500 Skype: Jupzchris
Posts: 27,880
|
Quote:
i get an error anywhere in partical i'd put that?
__________________
[email protected] |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
Confirmed User
Join Date: Nov 2005
Location: Metro Detroit
Posts: 748
|
as for removing spaces... you could always do urlencode($filename)
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 |
Too lazy to set a custom title
Industry Role:
Join Date: May 2003
Location: icq: 71462500 Skype: Jupzchris
Posts: 27,880
|
hmm
i changed it in php.ini but still says 2M in the phpinfo.php file do i gotta restart server
__________________
[email protected] |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 |
Too lazy to set a custom title
Industry Role:
Join Date: May 2003
Location: icq: 71462500 Skype: Jupzchris
Posts: 27,880
|
upload_max_filesize 100M 100M
:-D fixed restarted apache instead of whole server woo
__________________
[email protected] |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 |
Too lazy to set a custom title
Industry Role:
Join Date: May 2003
Location: icq: 71462500 Skype: Jupzchris
Posts: 27,880
|
hrmm it didnt seem to fix it woj
__________________
[email protected] |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 |
So Fucking Banned
Join Date: Jun 2003
Location: Wilsonville, Oregon
Posts: 468
|
you could also do a string replace, I like them much better
$value = str_replace(" ", "", $value); Pretty simple stuff. As far as the php.ini changes, you do have to restart apache. There is also a browser limitation that you'll run into, as well as timeout issues, with files that large. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#15 | |
Too lazy to set a custom title
Industry Role:
Join Date: May 2003
Location: icq: 71462500 Skype: Jupzchris
Posts: 27,880
|
Quote:
__________________
[email protected] |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#16 |
So Fucking Banned
Join Date: Jun 2003
Location: Wilsonville, Oregon
Posts: 468
|
Also, for your target path, make sure its a full path. Will make life easier.
Ex. /home/yoursite/public_html/uploads |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#17 | |
So Fucking Banned
Join Date: Jun 2003
Location: Wilsonville, Oregon
Posts: 468
|
Quote:
Now I'm not sure, but removing the spaces might actually cause it to fail. It may need to retain those spaces to know where the file is. Code:
<?php // Where the file is going to be placed $target_path = "uploads/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $filename = $_FILES['uploadedfile']['name']; $tempfilename = $_FILES['uploadedfile']['tmp_name']; $tempfilename = str_replace(" ","", $_FILES['uploadedfile']['tmp_name']); $target_path = "uploads/"; $target_path = $target_path . basename($filename); $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($tempfilename, $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#18 | |
Too lazy to set a custom title
Industry Role:
Join Date: May 2003
Location: icq: 71462500 Skype: Jupzchris
Posts: 27,880
|
Quote:
hmm did that and it renamed the file to s3v%20c.jpgs3v%20c.jpg lol ah well ill look at this with a fresh head tommrow
__________________
[email protected] |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#19 |
Beer Money Baron
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
|
preg_replace is a good option but you can consider renaming every file to a unique string too.
This line: Code:
$tempfilename = str_replace(" ","", $_FILES['uploadedfile']['tmp_name']); Code:
$tempfilename = preg_replace('/[^a-z0-9\ ]+/i','',$_FILES['uploadedfile']['tmp_name']); Code:
$tempfilename = uniqid('upload-'); Looks like you're using move_uploaded_file incorrectly. You want the first value to be the actual file that was uploaded, and the second value to be the new destination and name for it. So, should be: Code:
$target_path = $target_path . $tempfilename; if( move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#20 |
Beer Money Baron
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
|
Full code would then look something closer to this (Untested):
Code:
<?php # Full path to uploads, end with forward slash $target_path = "/path/to/uploads/"; if( !is_uploaded_file($_FILES['uploadedfile']['tmp_name']) ) { die("Invalid upload."); } $target_path = $target_path .$_FILES['uploadedfile']['tmp_name']; # Valid characters in filename are a-z, 0-9, or a dot $tempfilename = preg_replace('/[^a-z0-9\.]+/i','',$_FILES['uploadedfile']['tmp_name']); # Uncomment below if desiring a unique string filename instead # $tempfilename = uniqid('upload-'); $target_path = $target_path . $tempfilename; if( move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path) ) { echo "The file ".$_FILES['uploadedfile']['tmp_name']." has been uploaded to: ".basename($target_path); } else { echo "There was an error uploading the file, please try again!"; } ?>
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |