GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   php gurus question inside (https://gfy.com/showthread.php?t=643105)

Chris 08-10-2006 07:16 PM

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

woj 08-10-2006 07:17 PM

you need to change the setting via php.ini or .htaccess to increase the limit over 1 meg...

Chris 08-10-2006 07:19 PM

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?

woj 08-10-2006 07:21 PM

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...

Chris 08-10-2006 07:24 PM

damn woj you a gangsta

sho nuff max upload 2 megs

now time to break my server and edit that lol

woj 08-10-2006 07:26 PM

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

Tempest 08-10-2006 07:29 PM

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);

Chris 08-10-2006 07:34 PM

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 :)

Chris 08-10-2006 07:38 PM

Quote:

Originally Posted by Tempest
Code:

$filename=preg_replace("/\s+/g","",$filename);

hmm
i get an error
anywhere in partical i'd put that?

micker 08-10-2006 07:41 PM

as for removing spaces... you could always do urlencode($filename)

Chris 08-10-2006 07:44 PM

hmm

i changed it in php.ini but still says 2M in the phpinfo.php file


do i gotta restart server

Chris 08-10-2006 07:45 PM

upload_max_filesize 100M 100M

:-D fixed

restarted apache instead of whole server
woo

Chris 08-10-2006 08:39 PM

hrmm it didnt seem to fix it woj

heywood 08-10-2006 08:43 PM

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.

Chris 08-10-2006 08:44 PM

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

heywood 08-10-2006 08:45 PM

Also, for your target path, make sure its a full path. Will make life easier.

Ex. /home/yoursite/public_html/uploads

heywood 08-10-2006 08:54 PM

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.

Chris 08-10-2006 09:48 PM

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

Brujah 08-10-2006 11:15 PM

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 08-10-2006 11:25 PM

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

?>



All times are GMT -7. The time now is 11:51 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123