Jump to content

PHP Only Uploads From Same Directory


emmerac

Recommended Posts

Hi all, I'm a complete newb and I am getting really frustrated.  I am running the PHP that ships with Leopard.  I am using some basic PHP code to upload a file but it will only accept files from the same directory as the .php code, so if I try to upload a file from another computer to the server I get an file does not exist error!

 

<?php

if ((($_FILES["file"]["type"] == "image/gif")

|| ($_FILES["file"]["type"] == "image/jpeg")

|| ($_FILES["file"]["type"] == "image/pjpeg"))

&& ($_FILES["file"]["size"] < 20000))

  {

  if ($_FILES["file"]["error"] > 0)

    {

    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";

    }

  else

    {

    echo "Upload: " . $_FILES["file"]["name"] . "<br />";

    echo "Type: " . $_FILES["file"]["type"] . "<br />";

    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";

    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))

      {

      echo $_FILES["file"]["name"] . " already exists. ";

      }

    else

      {

      move_uploaded_file($_FILES["file"]["tmp_name"],

      "upload/" . $_FILES["file"]["name"]);

      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];

      }

    }

  }

else

  {

  echo "Invalid file";

  }

?>

Link to comment
Share on other sites

make sure permissions are okay on /uploads in terminal: chmod somedirectory 777, or in finder, get info, open the lock if necessary (lower right), then change all permissions to read and write.

 

p.s. I suggest that you use MAMP on Leopard and leave Apple's PHP/Apache alone. At least if you plan to make any mods/additions to PHP or plan to add MySQL.

 

 

 

Link to comment
Share on other sites

I switched over to XAMPP and I am still getting the same error from the same code:

 

Warning: file_get_contents(money.gif) [function.file-get-contents]: failed to open stream: No such file or directory in /Applications/xampp/xamppfiles/htdocs/geezum/s3up.php on line 16
Failed to read file money.gif

 

I have chmod to 777 the upload directory.  When I test it out I am simply trying to upload a small .gif that is sitting on my desktop and I get that error.  Any idea's?

Link to comment
Share on other sites

Ok, so I got the upload to work, but then after a few successful trial runs I started getting error 6 telling me that my tmp directory is not setup in my php.ini, but when I check my php.ini I see that I have it set to a /tmp folder in the /xamppfiles directory.  What the heck is going on here?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.