title: PHP: Upload an image with image name prepended by HTTP Path?
body: <p>I have the following php which uploads image to server with name inserted in database:</p>
  
  <pre><code>&lt;?php
  
  //Uploading File to server php folder//
  $uploaddir = ''; //Uploading to same directory as PHP file
  
  $file = basename($_FILES['userfile']['name']);
  
  $uploadFile = $file;
  
  $randomNumber = rand(0000, 99999); 
  
  $newName = $uploaddir . $randomNumber . $uploadFile;
  
  if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
  echo "Temp file uploaded. \r\n";
   } 
  
  else {
  echo "Temp file not uploaded. \r\n";
  }
  
  
  if (move_uploaded_file($_FILES['userfile']['tmp_name'], $newName)) {
  $postsize = ini_get('post_max_size'); 
  $canupload = ini_get('file_uploads');  
  $tempdir = ini_get('upload_tmp_dir'); 
  $maxsize = ini_get('upload_max_filesize');
  echo "http://localhost/abc/images/{$newName}" . "\r\n" . $_FILES['userfile']['size'] .    "\r\n" . $_FILES['userfile']['type'] ;
  }
  
  
  
  //Making sql db connection to store image path in db table//
  
  $host = "localhost";
  
  $username = "root";
  $password = "****";
  
  $database = "userauth";
  
  mysql_connect($host, $username);
  
  mysql_select_db($database) or die("Unable to find database");
  
  $image = $_GET["images"];
  
  $qry = "INSERT INTO image VALUES ('','$newName')";
  
  mysql_query($qry);
  
  mysql_close();
      ?&gt;
  </code></pre>
  
  <p>The above code easily uploads files with temporary name: upload_image prepended by random number to the following xampp folder path: <a href="http://localhost/abc/images/" rel="nofollow">http://localhost/abc/images/</a></p>
  
  <p>In the db table, i rev the image name as 'randomnumber'upload_image.jpg.
  What I need is that I need the db table to display image name along with the full path as <a href="http://localhost/abc/images/" rel="nofollow">http://localhost/abc/images/</a>'rand.number'upload_image.jpg</p>
  
  <p>How am I able to achieve this?</p>
  
  <p>I tried to replace uploaddir with "http://localhost/abc/images/" and tried to add it to the new file name but it returned the following warning:</p>
  
  <pre><code>&lt;b&gt;Warning&lt;/b&gt;:  move_uploaded_file(http://localhost/abc/images/33760upload_image.jpg)   [&lt;a href='function.move-uploaded-file'&gt;function.move-uploaded-file&lt;/a&gt;]: failed to open   stream: HTTP wrapper does not support writeable connections in    &lt;b&gt;/Applications/XAMPP/xamppfiles/htdocs/xampp/abc/images/imageupload.php&lt;/b&gt; on line    &lt;b&gt;24&lt;/b&gt;&lt;br /&gt;
  &lt;br /&gt;
  &lt;b&gt;Warning&lt;/b&gt;:  move_uploaded_file() [&lt;a href='function.move-uploaded-file'&gt;function.move-uploaded-file&lt;/a&gt;]: Unable to move '/Applications/XAMPP/xamppfiles/temp/phpdlCc5N' to 'http://localhost/abc/images/33760upload_image.jpg' in &lt;b&gt;/Applications/XAMPP/xamppfiles/htdocs/xampp/abc/images/imageupload.php&lt;/b&gt; on line   &lt;b&gt;24&lt;/b&gt;
  &lt;br /&gt;
  </code></pre>
  
  <p>Valuable guidance required.</p>
  
  <p>PS: PERMISSIONS ARE SET TO READ AND WRITE
      Table contains two fields: ID and Image with ID set to primary and auto increment</p>