The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
Replacing space with "_" when UL a file
]Hello everybody
have a little problem here. I wrote a little script to upload/download files to one specific folder on my host. problem is : u can upload files with space in the filename, but then u can't download it, it will link to somethink like : http://www.bla.com/upload/bo instead of http://www.bla.com/upload/bo om.jpg So I though that there may be a function replacing space with %20 or simple "_". I tried to add Code:
$file1=str_replace(" ","_",$file); Code:
@copy($file1, "$absolute_path/$file_name") I know it's really simple... but I can't hit it... :cross-eyed: Can anyone help pls? Thanx! |
#2
|
||||
|
||||
]
Code:
There?re strip_tags(), stripslashes and stripcslashes ? why not a stripspaces() function too? Here it is. function stripspaces($tex) { return(str_replace(" ","",$tex)); } |
#3
|
||||
|
||||
]have also tried to link to file as
Code:
<a href=$dl/$file1>blabla</a> Code:
$file1=str_replace(" ","_",$file); |
#4
|
||||
|
||||
$file = strtr($file, " ", "_");
should help.. Also your both examples seem correct to me in the first look. Are you sure you didnt miss another thing? For example in your code you assigned the modified name to variable "$file1". Are you sure you use the variable "$file1" instead of $file after you replaced the chars.. As for calling your function, this is the line you should use: $file=stripspaces($file); |
#5
|
||||
|
||||
]it worked! thanx a lot
just one last problem (really last one) file called bom'b'a.jpg after uploading will be called bom\-b\-a.jpg if I add Code:
$file=str_replace("'","-",$file); |
#6
|
||||
|
||||
]
Quote:
I use Code:
$dir = opendir($absolute_path); while($file = readdir($dir)) { if (($file != "..") and ($file != ".")) { $file=str_replace(" ","%20",$file); $list .= "$file" echo $list; Now I tried to add size ( $size ) of the file right after name of the file ( $file ) by using this script: Code:
// $size is the filesize (in bytes) function rendersize($size) { $type = 'bytes'; if ($size > '1023') { $size = $size/1024; $type = 'KB'; } if ($size > '1023') { $size = $size/1024; $type = 'MB'; } if ($size > '1023') { $size = $size/1024; $type = 'GB'; } if ($size > '1023') { $size = $size/1024; $type = 'TB'; } // Fix decimals and stuff if ($size < '10') $size = intval($size*100)/100; else if ($size < '100') $size = intval($size*10)/10; else $size = intval($size); // Comment the following line if you want X.XX KB displayed instead of X,XX KB $size = str_replace("." , "," , $size); return "$size $type"; } I tried some variants like Code:
$list .= "$file $size $type" I'm sure I'm inserting that script in the wrong place or I have to remove Code:
return "$size $type"; |
#7
|
||||
|
||||
Quote:
PHP Code:
|
#8
|
||||
|
||||
The function requires to be called WITH a $size variable so as to return a result.
For example if the file size is kept in a variable called $file_size then you should replace line: $list .= "$file" AS $list .= $file." (".rendersize($file_size).")"; As you see, you first send the file size to the function and then it returns it as "X Mb.". |
#9
|
||||
|
||||
for the size-part, you can stick the function wherever you want, but to actually get any output from it, you'll have to call it
try $size = rendersize (filesize ($file)); or maybe filesize ($absolutepath.$file) in your case... The parameter to the filesize-function has to be the filename with an absolute path. |
#10
|
||||
|
||||
Hmm - guess you beat me to it :P
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|