Page 1 of 1

basename returning unusual value <SOLVED>

Posted: Thu Oct 18, 2007 9:23 pm
by PastorHank
I have a form where I gather a filename which has the complete path. I then upload the file using the following

Code: Select all

<?php
   define ("FILEREPOSITORY","../stories");

   if (is_uploaded_file($_FILES['classnotes']['tmp_name'])) {

      if ($_FILES['classnotes']['type'] != "application/pdf") {
         echo "<p>Notes must be uploaded in PDF format.</p>";
     	 } else {
/* I am trying to avoid having the user re-enter the filename *?
/* if they manually enter the target filename on the form $name works fine */
         $name = $_POST['name'];
/*  */

         $captiontouse = $_POST['captionforfile'];
         $testname=basename($_FILES['classnotes']['tmp_name']) ;
         var_dump($testname);
         
         $result = move_uploaded_file($_FILES['classnotes']['tmp_name'], FILEREPOSITORY."/$name.pdf");
var_dump returns string(9) "phpARIf3f"
How can I grab the actual filename and automatically assign it to $name?

Thank you

Posted: Thu Oct 18, 2007 9:47 pm
by jeffery
$_FILES['classnotes']['name'] should contain the name of the uploaded file: http://php.net/manual/en/features.file-upload.php

Posted: Thu Oct 18, 2007 10:11 pm
by PastorHank
Thank you. I can't tell ya'll how much I appreciate having multiple sets of eyes and such a wide range of knowledgable folks around to help.

Posted: Thu Oct 18, 2007 10:18 pm
by Christopher
I would recommend doing this to discover what is in the superglobal you are working with:

Code: Select all

var_dump($_FILES);

Posted: Fri Oct 19, 2007 8:09 am
by PastorHank
That's a very good idea since I find myself using more and more

Posted: Fri Oct 19, 2007 11:01 am
by RobertGonzalez
It might sound a little weird at first, but a lot of coders put a little function together akin to:

Code: Select all

<?php
function getInfo($var) {
   echo '<pre>'; var_dump($var); echo '</pre>';
}
?>
Just so they have a little dumper around when they need it.