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

  • SEARCH
  • Home
  • 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 7080431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:47:40+00:00 2026-05-28T06:47:40+00:00

I’m a newbie programmer doing his best to self learn PHP. I’m trying to

  • 0

I’m a newbie programmer doing his best to self learn PHP. I’m trying to get a file upload to work, and I’m having some problems. The file seems to successfully upload, but it’s temporary location is a location that doesn’t exist on the server.

Here’s the code I’m using to upload the file:

<?php       
if (isset($_POST['submit']))
{
$imgfile = $_FILES['imgfile']['name'];
$temp = $_FILES['imgfile']['tmp_name'];
$type = $_FILES['imgfile']['type'];

if (!empty($imgfile))
{
        $dbc = mysqli_connect('DB_HOST','DB_USER','DB_PASSWORD','DB_NAME')
    or die('Error connecting to database');
    $query = "INSERT INTO photos VALUES(0, '$imgfile',NOW(), '$temp', '$type')";

        mysqli_query($dbc,$query);

        //clear the form                    
    $imgfile = "";

        mysqli_close($dbc);
    }
}
?>
<form enctype = "multipart/form-data" method = "POST" action = "<?php
echo $_SERVER['PHP_SELF']; ?>">

<label for = "imgfile">Filename:</label>
<input type = "file" id = "imgfile" name = "imgfile"  />
<br />
<input type = "submit" value = "upload" name = "submit" id = "submit" /> 
</form>

These are some examples of locations that the $_FILES['tmp_name'] variable says it’s being stored:

/tmp/phpWw6aut

or

/tmp/php4bzVfE

The default temporary directory set in the php.ini file is root/tmp. So that part is right, but then there’s that weird /phpgarbage folder supposedly inside the tmp folder that each file is saying that it’s in. Only thing is, that those folders don’t exist on the server.

Any thoughts? Let me know if there’s anything I can be more specific about. This is a first time programming related post for me, so let me know if there’s any more information I should be sharing.

Thank you for your time!

  • 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-05-28T06:47:41+00:00Added an answer on May 28, 2026 at 6:47 am

    You have to save the image in order to be able to access it later. To do this, add the following code:

    $path = "uploads/images/";
    if (is_uploaded_file($_FILES['imgfile']['tmp_name'])) {
        move_uploaded_file($_FILES["imgfile"]["tmp_name"], $path . $_FILES["imgfile"]["name"]);
    }
    

    after the following lines:

    if (!empty($imgfile))
    {
    

    Note that the $path must be writeable. And now the filename becomes $path.$_FILES["imgfile"]["name"]. Also make sure to implement some security checks, your code is vurnerable.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported

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.