i have this script that is meant to move a file from one folder to another but i get an error,:
$photo= $_POST['camera']; // i.e. 45647.jpg
//move file to userpics/ folder
rename ("../uploads/$photo", "../userp开发者_C百科ics/$photo");
but i get this error:
Warning: rename(/uploads/1czcec43s.jpg\n,/userpics/1czcec43s.jpg\n) [function.rename]: No error in .. on line 24
Your filenames are containing linebreaks \n
. This may well be the source of the error. Try calling trim
:
$photo = trim($_POST['camera']); // i.e. 45647.jpg
rename ("../uploads/$photo", "../userpics/$photo");
Also, for goodness sake add some sanity checking to your code. Your user could easily put web/index.php
(for instance) as the contents of $_POST['camera']
and overwrite your PHP file.
There are an \n (linefeed) at the end of the used POST parameter. Have you tried remove it?
Notice: the presented code is highly vulnerable.
精彩评论