Problems with file upload when going from localhost to web host

2.8k views Asked by At

How to upload an image on the internet? right now the script below works on local host but i have issues when its hosted. any one have any ideas?

<?php
// form in which we can upload the image
session_start();

include("connect.php");

// session as on website.

$jobseekerid = $_SESSION['jobseekerid'];

if($_POST['submit'])
{
    //get file attributes
    $name = $_FILES['myfile']['name'];
    $tmp_name = $_FILES['myfile']['tmp_name'];


    if ($name)
    {
       // start upload process
       $location ="pictures/$name";
       move_uploaded_file($tmp_name,$location);
// updating table users (setting image locaion
       $query = mysql_query("UPDATE jobseekers SET imagelocation='$location' WHERE jobseekerid='$jobseekerid'");

       die("Your avatar has been uploaded! <a href='profile.php'>Go back to view</a>");


    }
    else

        die("Please Select a file!");

}

echo "Welcome, ".$_SESSION['username']."!<br><a href='logout.php'>Logout</a>";

echo "Upload Your image:

<form action='upload.php' method='POST' enctype='multipart/form-data'>
File: <input type='file' name='myfile'> <input type='submit' name='submit' value='upload!'
>
</form>

";

?>
2

There are 2 answers

3
usr-local-ΕΨΗΕΛΩΝ On BEST ANSWER

A possible problem is that you don't have permissions to write into the target directory!!

Please check if you are able to with your provider. You may have to set FTP permissions 777 to upload directory or to choose a different upload path that is given by your ISP.

At least that is the most typical issue.

And please, next time format your questions better.

2
Greg On

You should get an error message explaining your problem. Some shared hosting platforms block PHP error messages by default, and these can be re-enabled at runtime with this code:

ini_set("display_errors", 1);

I am assuming that the usergroup that is running your PHP application does not have write access to the directory it is hosted in.

Depending on the operating system and hosting platform, there are various ways in granting these permissions.