Jump to content

Recommended Posts

Hi all Gurus:
I have not been able to make file upload work for about 2 days now and am at the end of my wits

-----------Code Snippet ----------------------
<?php
  require ('page.inc');
 
  // Check for error
  $userfile_error = $_FILES['userfile']['error'];
  if ( $userfile_error > 0)
  {
  $pagecontent =  $pagecontent . 'Problem :';
  switch ($userfile_error)
    {
      case 1:  $pagecontent =  $pagecontent . 'File exceeded upload_max_filesize';  break;
      case 2:  $pagecontent =  $pagecontent . 'File exceeded max_file_size';  break;
      case 3:  $pagecontent =  $pagecontent . 'File only partially uploaded';  break;
      case 4:  $pagecontent =  $pagecontent . 'No file uploaded';  break;
    }
    exit;
  }
 
  // Extract Form fields
  $userfile = $_FILES['userfile']['name'];
  // Check the input values 
  if ( empty($userfile))
  {
  echo 'One of the required fields was empty, please check and try again';
  }
  else
  {
  // Put the file where we want it
  $upfile = '/uploads/' . $userfile; 
 
  $tmpfile = 'c:\\wamp\\tmp\\' . basename($_FILES['userfile']['tmp_name']);
  echo $tmpfile . " <--- used basename and appended to the path <br>";
  echo $_FILES['userfile']['tmp_name'] . "<--- Original tmp file<br>";
  echo $_FILES['userfile']['name'] . " <--- FILES name var <br>";
  echo $_FILES['userfile']['size'] . " <--- FILES size var<br>";
  $pagecontent = $pagecontent . $_FILES['userfile']['type'] . " <--- FILES type var<br>";
 
  if (is_uploaded_file($_FILES['userfile']['tmp_name']))
  {
  if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile))
  {
  echo 'Error: Could not move file to destination directory.';
  }
  else
  {
  echo "<h2>Processing File:" . $upfile. "</h2>\n<br>";
  }
  }
  else
  {
  echo 'Error: Possible file upload attack :'. $_FILES;
  }
?>
-----------End Code Snippet ----------------------
and the results in the browser are

c:\wamp\tmp\php4B.tmp <--- used basename and appended to the path
c:/wamp/uploads\php4B.tmp<--- Original tmp file
angus_input.csv <--- FILES name var
1906 <--- FILES size var
text/plain <--- FILES type var
Error: Could not move file to destination directory.


with addtional warnings

Warning: move_uploaded_file(/uploads/angus_input.csv) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\wamp\www\GeoCoding\geocodecsv.php on line 49

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'c:/wamp/uploads\php4B.tmp' to '/uploads/angus_input.csv' in C:\wamp\www\GeoCoding\geocodecsv.php on line 49


Clearly the problem is the tmp upload file full path name which is 'c:/wamp/uploads\php4B.tmp'  (NOTICE the different slash direction)

How do I fix this? I tried stripslashes, tried re-constructing the tmp file and then providing it to function move_uploaded_file, but it still does not move it

Can anyone help? Thanks a lot in advance
-Venki
I fixed my own problem. I hardcoded the entire path instead of using the relative path for the destination filename and for some reason  it worked. All documentaion says that it is relative to where the php script executes. Anyway that was my fix if it helps anybody.

-Venki
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.