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.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 08-10-2006, 07:16 PM   #1
Chris
Too lazy to set a custom title
 
Chris's Avatar
 
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]
Chris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-10-2006, 07:17 PM   #2
woj
<&(©¿©)&>
 
woj's Avatar
 
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
woj is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-10-2006, 07:19 PM   #3
Chris
Too lazy to set a custom title
 
Chris's Avatar
 
Industry Role:
Join Date: May 2003
Location: icq: 71462500 Skype: Jupzchris
Posts: 27,880
Quote:
Originally Posted by woj
you need to change the setting via php.ini or .htaccess to increase the limit over 1 meg...
seriously? lol
default server is liek 1 meg or something?
__________________
[email protected]
Chris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-10-2006, 07:21 PM   #4
woj
<&(©¿©)&>
 
woj's Avatar
 
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
woj is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-10-2006, 07:24 PM   #5
Chris
Too lazy to set a custom title
 
Chris's Avatar
 
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]
Chris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-10-2006, 07:26 PM   #6
woj
<&(©¿©)&>
 
woj's Avatar
 
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
woj is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-10-2006, 07:29 PM   #7
Tempest
Too lazy to set a custom title
 
Industry Role:
Join Date: May 2004
Location: West Coast, Canada.
Posts: 10,217
Quote:
Originally Posted by Chris
i want it to remove the spaces in the file name when uploaded
Code:
$filename=preg_replace("/\s+/g","",$filename);
Tempest is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-10-2006, 07:34 PM   #8
Chris
Too lazy to set a custom title
 
Chris's Avatar
 
Industry Role:
Join Date: May 2003
Location: icq: 71462500 Skype: Jupzchris
Posts: 27,880
Quote:
Originally Posted by woj
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
yeah gonna throw it behind some htaccess
__________________
[email protected]
Chris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-10-2006, 07:38 PM   #9
Chris
Too lazy to set a custom title
 
Chris's Avatar
 
Industry Role:
Join Date: May 2003
Location: icq: 71462500 Skype: Jupzchris
Posts: 27,880
Quote:
Originally Posted by Tempest
Code:
$filename=preg_replace("/\s+/g","",$filename);
hmm
i get an error
anywhere in partical i'd put that?
__________________
[email protected]
Chris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-10-2006, 07:41 PM   #10
micker
Confirmed User
 
Join Date: Nov 2005
Location: Metro Detroit
Posts: 748
as for removing spaces... you could always do urlencode($filename)
micker is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-10-2006, 07:44 PM   #11
Chris
Too lazy to set a custom title
 
Chris's Avatar
 
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]
Chris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-10-2006, 07:45 PM   #12
Chris
Too lazy to set a custom title
 
Chris's Avatar
 
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]
Chris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-10-2006, 08:39 PM   #13
Chris
Too lazy to set a custom title
 
Chris's Avatar
 
Industry Role:
Join Date: May 2003
Location: icq: 71462500 Skype: Jupzchris
Posts: 27,880
hrmm it didnt seem to fix it woj
__________________
[email protected]
Chris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-10-2006, 08:43 PM   #14
heywood
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.
heywood is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-10-2006, 08:44 PM   #15
Chris
Too lazy to set a custom title
 
Chris's Avatar
 
Industry Role:
Join Date: May 2003
Location: icq: 71462500 Skype: Jupzchris
Posts: 27,880
Quote:
Originally Posted by heywood
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.
i am smashing my head against the wall with this one
__________________
[email protected]
Chris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-10-2006, 08:45 PM   #16
heywood
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
heywood is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-10-2006, 08:54 PM   #17
heywood
So Fucking Banned
 
Join Date: Jun 2003
Location: Wilsonville, Oregon
Posts: 468
Quote:
Originally Posted by Chris
i am smashing my head against the wall with this one
This should simplify it a bit.

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!";
}

?>
One thing you could do is, put a file renaming function in there.

Last edited by heywood; 08-10-2006 at 08:55 PM..
heywood is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-10-2006, 09:48 PM   #18
Chris
Too lazy to set a custom title
 
Chris's Avatar
 
Industry Role:
Join Date: May 2003
Location: icq: 71462500 Skype: Jupzchris
Posts: 27,880
Quote:
Originally Posted by heywood
This should simplify it a bit.

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!";
}

?>
One thing you could do is, put a file renaming function in there.


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]
Chris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-10-2006, 11:15 PM   #19
Brujah
Beer Money Baron
 
Brujah's Avatar
 
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']);
Would probably be better as something like this:
Code:
$tempfilename = preg_replace('/[^a-z0-9\ ]+/i','',$_FILES['uploadedfile']['tmp_name']);
or this:
Code:
$tempfilename = uniqid('upload-');
http://us2.php.net/uniqid

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)) {
Depending on your use for this, you might also want to add a test in there to see if the file exists already first before overwriting it.
__________________
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-10-2006, 11:25 PM   #20
Brujah
Beer Money Baron
 
Brujah's Avatar
 
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!";
}

?>
__________________
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.