Uploaded fielname as variable

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
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Uploaded fielname as variable

Post by mesz »

Help!
I'm trying something real basic but I've been working at it for 8 hours+ with no light at the end of the tunnel.
All I want to do is upload a file ( mp3 ultimately, but any file will do ), and use the filename of this uploaded file, as a variable to be written into a .dat file.
When I have this filename written in the .dat file I can use it as part of a URL to link to the file.
But at the moment I only get the actual variable written to the file.
ie
May 12, 2004, 6:33 pm|descriptive words|$file_url
Please help...I make no money out of the site I run...so you won't be lining my pockets by sharing your knowledge!
This is what I have so far.

Code: Select all

<?php
$imagesdir = "../mp3/updir/";
$fp = fopen('../mp3/news.dat','a+');
$file_name = $_FILES['userfile']['name']; 
$file_url  = "../mp3/updir/".$file_name;

if($HTTP_POST_VARS['submit'])
         {
                  $line = date ("F j, Y, g:i a"). "|" . $HTTP_POST_VARS['desc']. "|" . $HTTP_POST_VARS['tree'];

                  $line = str_replace("\r\n","<br>",$line);
                  $line = stripslashes($line);

                  $line .= "\r\n";
                  fwrite($fp, $line);

                  if (isset($_FILES['userfile'])) {
if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $imagesdir . $_FILES['userfile']['name'])) ;
{

				      echo ' ';
				    } 
				  } else {
				  echo'';
}

            }
$foom = $fishbaggerss
?>

Code: Select all

&lt;FORM ACTION="&lt;?php echo $_SERVER&#1111;'PHP_SELF']; ?&gt;" METHOD="POST" enctype="multipart/form-data" NAME="mp"&gt;

Upload MP3 File
&lt;input type="file" name="userfile" id="userfile" &gt;
&lt;br&gt;

Description;
&lt;BR&gt;
&lt;TEXTAREA COLS="50" ROWS="2" NAME="desc"&gt;
&lt;/TEXTAREA&gt;
&lt;br&gt;
&lt;input type="hidden" name="tree" value=$file_url&gt;


&lt;BR&gt;
&lt;BR&gt;
&lt;INPUT TYPE="reset" NAME="reset" VALUE="r e s e t"&gt;
&lt;INPUT TYPE="submit" NAME="submit" VALUE="P O S T"&gt;
&lt;BR&gt;
&lt;/FORM&gt;
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

perhaps changing:

Code: Select all

............
<input type="hidden" name="tree" value=$file_url> 
............
to

Code: Select all

.............
<input type="hidden" name="tree" value="<?php echo $file_url;?>"> 
.............
will do it
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

nop, I was wrong :)

Code: Select all

// change this line
$line = date ("F j, Y, g:i a"). "|" . $HTTP_POST_VARS['desc']. "|" . $HTTP_POST_VARS['tree']; 
// to
$line = date ("F j, Y, g:i a"). "|" . $HTTP_POST_VARS['desc']. "|" . $file_url;
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post by mesz »

Thank you my man.
So <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> simple.
I should probsably have gone out for lunch instead of just slamming my keyboard about...you know, that old
' can't see the woods for the trees '
thing.

If you want to know about the basic script for viewing the details from the .dat file, here you go:

Code: Select all

<?php
$data = file('../mp3/news.dat');
$data = array_reverse($data);
foreach($data as $element) {
    $element = trim($element);
    $pieces = explode("|", $element);
echo
 $pieces[0] . $pieces[1]. "<a href="$pieces[2] " target="_blank">$pieces[2]</a>"  ;
}
?>
Cheers again.
Post Reply