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 8901317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:19:16+00:00 2026-06-15T01:19:16+00:00

I have an upload form in a php page , that puts a csv

  • 0

I have an upload form in a php page , that puts a csv file into a database.

I’m getting an error upon submission of my csv file:

Warning: move_uploaded_file(/public_html/csv/test/books.csv) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/blakeloi/public_html/csv/index.php on line 19

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpZw2e2X' to '/public_html/csv/test/books.csv' in /home/blakeloi/public_html/csv/index.php on line 19

This is the line that is wrong:

$upload_path = '/Users/blakeloizides/Desktop';

In:

if (move_uploaded_file($_FILES['file']['tmp_name'], $upload_path.'/'.$_FILES['file']['name']))

I have tried renaming my file path many times now, and nothing seems to work. The most obvious answer would be that my file directory path is wrong , but I put the folder into my browser and got the correct path. I even tried to use a folder on my server /public_html/test, but this did not work.

<?php

$message = null;

$allowed_extensions = array('csv');

$upload_path = '/Users/blakeloizides/Desktop';

if (!empty($_FILES['file'])) {

if ($_FILES['file']['error'] == 0) {

    // check extension
    $file = explode(".", $_FILES['file']['name']);
    $extension = array_pop($file);

    if (in_array($extension, $allowed_extensions)) {

        if (move_uploaded_file($_FILES['file']['tmp_name'], $upload_path.'/'.$_FILES['file']['name'])) {

            if (($handle = fopen($upload_path.'/'.$_FILES['file']['name'], "r")) !== false) {

                $keys = array();
                $out = array();

                $insert = array();

                $line = 1;

                while (($row = fgetcsv($handle, 0, ',', '"')) !== FALSE) {

                    foreach($row as $key => $value) {
                        if ($line === 1) {
                            $keys[$key] = $value;
                        } else {
                            $out[$line][$key] = $value;

                        }
                    }

                    $line++;

                }

                fclose($handle);    

                if (!empty($keys) && !empty($out)) {

                    $db = new PDO('mysql:host=localhost;dbname=blakeloi_import-csv', 'blakeloi_root', 'password');
                    $db->exec("SET CHARACTER SET utf8");

                    foreach($out as $key => $value) {

                        $sql  = "INSERT INTO `books` (`";
                        $sql .= implode("`, `", $keys);
                        $sql .= "`) VALUES (";
                        $sql .= implode(", ", array_fill(0, count($keys), "?"));
                        $sql .= ")";
                        $statement = $db->prepare($sql);
                        $statement->execute($value);

                    }

                    $message = '<span class="green">File has been uploaded successfully</span>';

                }   

            }

        }

    }     else {
        $message = '<span class="red">Only .csv file format is allowed</span>';
    }

} else {
    $message = '<span class="red">There was a problem with your file</span>';
}

}

?>
    <!DOCTYPE HTML>
    <html lang="en">
    <head>
<meta charset="utf-8" />
<title>Upload CSV to MySQL</title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<link href="css/core.css" rel="stylesheet" type="text/css" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>

<section id="wrapper">  

<form action="" method="post" enctype="multipart/form-data">

    <table cellpadding="0" cellspacing="0" border="0" class="table">
        <tr>
            <th><label for="file">Select file</label> <?php echo $message; ?></th>
        </tr>
        <tr>
            <td><input type="file" name="file" id="file" size="30" /></td>
        </tr>
        <tr>
            <td><input type="submit" id="btn" class="fl_l" value="Submit" /></td>
        </tr>
    </table>

</form>

</section>

</body>
</html>

enter image description here

My index.php file is sitting in public_html/csv or http://www.blakeloizides.co.za/csv
and I want to upload the file to public_html/csv/test or http://www.blakeloizides.co.za/csv/test

My permissions are 755 for both folders.

enter image description here

  • 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-15T01:19:17+00:00Added an answer on June 15, 2026 at 1:19 am

    I had to change my file path to /home/blakeloi/public_html/csv/test . That was my error I was using /public_html/csv/test

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

Sidebar

Related Questions

http://pastebin.com/dttyN3L6 The file that processes the form is called upload.php I have never really
I have an upload box... <form action=upload_file.php method=post enctype=multipart/form-data><BR> <label for=file>Filename:</label><BR> <input type=file name=file
I have a PHP validate statement for a file upload on a HTML form.
I have created a form to upload a a newsletter into the database. I'm
I have a simple PHP upload page that when finished uploading runs a bit
I have a import file page that has a form with a file input
I have a form that's calling a Post a .php file, which i though
I have a Form that I am using to receive an uploaded .csv file,
I have an upload form with a file to be uploaded. The issue I
I have an upload form that takes a user about 30 min. to complete.

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.