I am having a problem moving files uploaded using POST.

What is supposed to happen is it takes two files, a picture and its
associated thumbnail, both of which have been uploaded via HTTP POST,  and
moves them to two different folders, renaming them appropriately.

Here's the code...

-----------------------------------------------------------
BEGIN CODE FRAGMENT
-----------------------------------------------------------

function upload($pid) {
 GLOBAL $siteroot, $HTTP_POST_FILES, $fileroot;

 // more manageable variable names to work with
 $picfile = $HTTP_POST_FILES['picfile']['tmp_name'];
 $thumbfile = $HTTP_POST_FILES['thumbfile']['tmp_name'];
 $pic = $HTTP_POST_FILES['picfile']['name'];
 $thumb = $HTTP_POST_FILES['thumbfile']['name'];

 // check if *pictures* were uploaded, as opposed to some other file type
 if(!$picsize = getimagesize($picfile) || !$thumbsize =
getimagesize($thumbfile) ) {
  $error[] = "Either the picture was not uploaded properly, or ".
     "it was not a valid picture. Please hit 'back' and try ".
     "again.";
 }

 // get the file extension of the pictures
 $picext = strstr($pic, ".");
 $thumbext = strstr($thumb, ".");

 // create the filenames pictures will be stored under
 $picname = "pic" . $pid . $picext;
 $thumbname = "thumb" . $pid . $thumbext;

 // destination path for pictures and thumbnails
 $picdest = "$fileroot/pictures/$picname";
 $thumbdest = "$fileroot/thumbs/$thumbname";

 // debug info
 $message = "<b>Picture Source:</b> $picfile<br>\n".
    "<b>Picture Dest:</b> $picdest<br><br>\n\n".
    "<b>Thumbnail Source:</b> $thumbfile<br>\n".
    "<b>Thumbnail Dest:</b> $thumbdest<br><br>\n\n";

 message($message);

 // security check then copy files to destination folder...
 if (!is_uploaded_file($picfile) || !is_uploaded_file($thumbfile) ) {
  $error[] = "Possible File Upload attack. File Upload aborted.";
 } elseif (!$movepic = copy($picfile, $picdest) || !$movethumb =
copy($thumbfile, $thumbdest) ) {
  // ... or quit with error
  $error[] = "File could not be copied. Please retry.<br>\n".
     "<b>Picture Source:</b> $picfile<br>\n".
     "<b>Picture Dest:</b> $picdest<br><br>\n\n".
     "<b>Thumbnail Source:</b> $thumbfile<br>\n".
     "<b>Thumbnail Dest:</b> $thumbdest<br><br>\n\n".
     "Picture: $movepic<br> Thumbnail: $movethumb";

 }

 // check for errors or write successful entry to dbase
 if(isset($error) ) {
  error($error);
 } else {
  $db = open_db();

  $query = "UPDATE yb_pictures SET ".
       "thumburl='" . $thumbname . "', ".
       "picurl='" . $picname . "', ".
       "status='3' ".
       "WHERE id='" . $pid . "'";
  $result = query($query, $db);

  // output for user
  $message = "Picture uploaded successfully. Please ".
     "<a href=\"$siteroot/manager.php\">go back to the Site ".
     "Manager.";
  message($message);
 }
}

-----------------------------------------------------------
END CODE FRAGMENT
-----------------------------------------------------------

My problem is that the script completes successfully and reports "Picture
uploaded successfully". But when I go to see if the files are there, the
thumbnail file is missing. Only the picture file appears where it should.

I have checked, re-checked and checked again for typos or other errors in
the file or directory names, and I am sure there are none.

I have no idea what could be the problem.

Go to http://www.unndunn.com/guestbook.php?action=showVersionInfo for info
about the version of PHP the server is running.

Thanks in advance!

--
Uchendu Nwachukwu
newsreply AT unndunn DOT com - www.unndunn.com





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to