PHP rename() not working <p>I am trying to rename a duplicate file name upon upload of a new file with the same name. Everything is working great except for that I am getting an error:</p> <pre><code>&lt;b&gt;Warning&lt;/b&gt;: rename(./uploads/484360_438365932885330_1444746206_n.jpeg,): No such file or directory in &lt;b&gt;/home/unisharesadmin/public_html/wp-content/themes/blankslate/check_duplicate_img.php&lt;/b&gt; on line &lt;b&gt;36&lt;/b&gt;&lt;br /&gt; </code></pre> <p>Despite confirming that the directory exists and that the file and directory are both writeable, PHP is still throwing this error. I have consulted countless threads on here already and none of them seem to help, as I cannot find any path or string error with my file path.</p> <p>Thank you for any help you can provide!</p> <p>Cheers Colin</p> <p>Code:</p> <pre><code>&lt;? require_once('../../../wp-config.php'); function RandomString($length = 10) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i &lt; $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; } ?&gt; </code></pre>