0

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>

";

?>
usr-local-ΕΨΗΕΛΩΝ
  • 26,101
  • 30
  • 154
  • 305
ope
  • 47
  • 3
  • 10
  • What are the 'issues'? We can't help you without a description of your problem. – Delan Azabani Mar 01 '11 at 10:02
  • Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpKvpKuX' to 'pictures/phone.jpg' in /home/a8752996/public_html/upload.php on line 67 thats the error am getting – ope Mar 01 '11 at 10:20

2 Answers2

2

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.

usr-local-ΕΨΗΕΛΩΝ
  • 26,101
  • 30
  • 154
  • 305
  • Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpKvpKuX' to 'pictures/phone.jpg' in /home/a8752996/public_html/upload.php on line 67 thats the error am getting. my bad about the format of the questions. – ope Mar 01 '11 at 10:18
  • It is really a good idea to put 777 to the upload directory..? – Eduard7 Mar 01 '11 at 11:23
  • Obviously not, but that's the quickest solution – usr-local-ΕΨΗΕΛΩΝ Mar 01 '11 at 13:18
0

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.

Greg
  • 21,235
  • 17
  • 84
  • 107
  • Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpKvpKuX' to 'pictures/phone.jpg' in /home/a8752996/public_html/upload.php on line 67 ......thats the error am getting. – ope Mar 01 '11 at 10:19
  • I am assuming that the usergroup that is running your PHP application does not have write access to the directory it is hosted in. – Greg Mar 01 '11 at 21:47