I have to remove% sign in the directory by file or image name that I use the string
< Code> $ oldfile = "../..papers /temp-uploaded/".$file; $ Newfile = "../wallpapers/temp-uploaded/" trim (str_replace ('%', '', $ file)); Rename ("$ oldfile", "$ newfile"); But this does not work, I use the wire (trim, str_replace does not work, how can I remove preg_replace and use it for $ amp; $$ etc Answer Back < / P>
with other things An issue can be because your argument is correct. Code> Rename ("$ oldfile", "$ newfile");
should be:
Rename ($ oldfile, $ newfile);and:
$ oldfile = "../wallpapers/temp-uploaded/ ". $ File; < / Code>should be:
$ oldfile = '../wallpapers/temp-uploaded/'.file;Because there is no need for additional source: (See "double" (") vs. singles (')"). And.
Regarding this problem, You have to do some decent debugging:
Resize "resembles [$ oldfile] [$ newfile]";- Make sure That folder and old file exists
- What does
do- does the
file_get_contents ($ oldfile);file_put_contents ($ newfile, file_get_contents ($ oldfile));- Make sure you have write permissions for the folder. Typically
will be chmod 777.- Before rename, do the work:
if (file_exists ($ newfile)) {unlink ($ newfile); }As if you exist, you will have to delete the new file as it will be moving forward. Alternatively, if you do not want to replace, you can add something for the filename. You get this idea.Regarding the replacement question.
As you said you will remove the% xx value, it is best to first decode them:
$ file = trim ( Urldecode ($ file);You can use a regular expression again:
$ newfile = '../ wallpapers / temporary-upload /'. Preg_replace ('/ [\ \ & Amp; \\% \\ $ \\ s] + /', '-', $ file); Replace with / -and %$ or if you want to be more stringent:
$ newfile = '../wallpapers/temp - Upload / '. Preg_replace ('/ [^ a-zA-Z0- 9 _ \ - - \.] + /', '-', $ file); / / Find everything that does not have the character of your standard file name and replace it with one -to avoid the regex character
\\is probably those Not all characters are necessary for me, I have survived, but history has proved that you are better than sorry! ;-)
Comments
Post a Comment