Jump to content

Upload Script


Fallen_angel

Recommended Posts

I am having a little trouble with my upload script , it will work fine provided the script is in the same folder as the uploads folder , however as soon as I move it into the admin section of my site which is where i want it it stops working ,  I have tried to play with the $destfile variable in the script bellow but what apears to be correct to me simply isn't workign so If somoen coudl have a look and tell me where i am goign wrong i would really apreciate it

[code]<?php
//
// did the upload succeed or fail?
//
if ($_FILES['avatarfile']['error'] == UPLOAD_ERR_OK)
{
  //
  // verify (casually) that this appears to be an image file
  //
  $ext = strtolower(pathinfo($_FILES['avatarfile']['name'],
                            PATHINFO_EXTENSION));
  switch ($ext)
  {
    case 'jpg': case 'jpeg': case 'gif':
    case 'png': case 'bmp':
      break;  // file type is okay!
    default:
      throw new InvalidFileTypeException($ext);
  }

  //
  // move the file to the appropriate location
  //
  $destfile = '../foldername/uploads/' . basename($_FILES['avatarfile']['name'] );
  $ret = @move_uploaded_file($_FILES['avatarfile']['tmp_name'],
                            $destfile);
  if ($ret === FALSE)
    echo "Unable to move user photo!<br/>\n";
  else
    echo "Moved image to uploads directory<br/>\n";
}
else
{
  //
  // see what the error was.
  //
  switch ($_FILES['avatarfile']['error'])
  {
    case UPLOAD_ERR_INI_SIZE:
    case UPLOAD_ERR_FORM_SIZE:
      throw new FileSizeException();
      break;

    case UPLOAD_ERR_PARTIAL:
      throw new IncompleteUploadException();
      break;

    case UPLOAD_ERR_NO_FILE:
      throw new NoFileReceivedException();
      break;

    default:
      echo "say what?";
      break;
  }
}
?>[/code]

I know the script itself works fine as I can use it if they are within the same directory so I am pretty sure i have to be doign somethign wrong on the $destfile  line

thanx in advance to anyone that can help out

Link to comment
https://forums.phpfreaks.com/topic/26528-upload-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.