开发者

I get an error with moving files to different folders

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜