basename returning unusual value <SOLVED>

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

basename returning unusual value <SOLVED>

Post 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
Last edited by PastorHank on Thu Oct 18, 2007 10:13 pm, edited 1 time in total.
jeffery
Forum Contributor
Posts: 105
Joined: Mon Apr 03, 2006 3:13 am
Location: Melbourne, Australia
Contact:

Post by jeffery »

$_FILES['classnotes']['name'] should contain the name of the uploaded file: http://php.net/manual/en/features.file-upload.php
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I would recommend doing this to discover what is in the superglobal you are working with:

Code: Select all

var_dump($_FILES);
(#10850)
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

Post by PastorHank »

That's a very good idea since I find myself using more and more
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply