Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7857627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:05:44+00:00 2026-06-02T21:05:44+00:00

I have the following php which uploads image to server with name inserted in

  • 0

I have the following php which uploads image to server with name inserted in database:

<?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();
    ?>

The above code easily uploads files with temporary name: upload_image prepended by random number to the following xampp folder path: http://localhost/abc/images/

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 http://localhost/abc/images/‘rand.number’upload_image.jpg

How am I able to achieve this?

I tried to replace uploaddir with “http://localhost/abc/images/&#8221; and tried to add it to the new file name but it returned the following warning:

<b>Warning</b>:  move_uploaded_file(http://localhost/abc/images/33760upload_image.jpg)   [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: failed to open   stream: HTTP wrapper does not support writeable connections in    <b>/Applications/XAMPP/xamppfiles/htdocs/xampp/abc/images/imageupload.php</b> on line    <b>24</b><br />
<br />
<b>Warning</b>:  move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: Unable to move '/Applications/XAMPP/xamppfiles/temp/phpdlCc5N' to 'http://localhost/abc/images/33760upload_image.jpg' in <b>/Applications/XAMPP/xamppfiles/htdocs/xampp/abc/images/imageupload.php</b> on line   <b>24</b>
<br />

Valuable guidance required.

PS: PERMISSIONS ARE SET TO READ AND WRITE
Table contains two fields: ID and Image with ID set to primary and auto increment

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:05:45+00:00Added an answer on June 2, 2026 at 9:05 pm

    http://php.net/manual/en/reserved.variables.server.php

    with the $_SERVER array you can access some http request details, e.g. the path

    you should not try to move the uploaded file from / to an readonly protocol like http. instead just get it from the php tmp directory. also don’t start a filename like that while moving it, which causes your errors i think.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have index.php which uploads a file to server and sets several PHP variables
I have the following lines of php code which should rename a file which
I have a main.php file which has the following three included php files: <!--TAB
I have the following in a .htaccess file redirect 301 /page.php http://domain.com/page Which works
I have the following code: <div><strong>Name: </strong><?php echo anchor('http://'.$link, $row->Name); ?></div> Which takes a
I have the following PHP code which works out the possible combinations from a
I have the following mysql query which I am running with php like so.
I have the following code: http://www.nomorepasting.com/getpaste.php?pasteid=22615 Which is called by the javascript mentioned in
I have the following URLs with the same content: http://www.mysite.com/forum/viewthread.php?thread_id=39&pid=1349 http://www.mysite.com/forum/viewthread.php?forum_id=2&thread_id=39 Which at the
I have the following PHP code which simply grabs a URL behind HTTP-Basic authentication

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.