Я пытаюсь переименовать дубликат имени файла при загрузке нового файла с тем же именем. Все работает прекрасно, за исключением, что я получаю сообщение об ошибке:PHP rename() не работает
<b>Warning</b>: rename(./uploads/484360_438365932885330_1444746206_n.jpeg,): No such file or directory in <b>/home/unisharesadmin/public_html/wp-content/themes/blankslate/check_duplicate_img.php</b> on line <b>36</b><br />
Несмотря на подтверждение того, что каталог существует и что файл и каталог оба записываемые, PHP по-прежнему бросает эту ошибку. Я уже консультировался с бесчисленными потоками, и ни один из них, похоже, не помогает, поскольку я не могу найти какой-либо путь или строчную ошибку в моем пути к файлу.
Благодарим за помощь, которую вы можете предоставить!
Приветствия Colin
Код:
<?
require_once('../../../wp-config.php');
function RandomString($length = 10) {
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
$this_img = $_REQUEST['filename'];
$path = './uploads/' . $this_img;
$img_array = explode(".", $this_img);
$new_img = RandomString() . '.' . $img_array[sizeof($img_array)-1];
$new_path = './uploads/' . $new_img;
if (file_exists($path))
{
query_posts('posts_per_page=-1');
while(have_posts())
{
the_post();
if(strpos(get_post_meta(get_the_id(), 'imgurl1')[0], $this_img) !== false)
{
//echo "this posts url1 matches, so update the existing files name and the posts refrence to it";
echo is_writeable("./uploads");
rename($path, $newpath);
//echo update_post_meta(get_the_id(), 'imgurl1', get_template_directory_uri() . '/uploads/' . $new_img);
}
else if(strpos(get_post_meta(get_the_id(), 'imgurl2')[0], $this_img) !== false) //this posts url2 matches
{
echo "this posts url2 matches, so update the existing files name and the posts refrence to it";
//rename($path, $newpath);
//echo update_post_meta(get_the_id(), 'imgurl2', get_template_directory_uri() . '/uploads/' . $new_img);
}
}
}
else
{
echo 0;
}
?>
Итак, где еда? Я имею в виду код? – user5173426
@HawasKaPujaari просто пришлось быстро переформатировать код. См. Мой обновленный вопрос – colinmcp