Jump to content

Making Variables (or array elements?) into File Paths? +tagging!


Zeradin

Recommended Posts

I have an upload form:

<html>
<body>
<?php 
$uploadf = array(); 
?>

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>

 

and a php upload script:

<?php
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("images/media/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "images/media/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "images/media" . $_FILES["file"]["name"];
      }
    }
?>

 

I want to add a

$uploadf = array();
$uploadf['path'] = 'images/media";

to the upload form and then use it like

 

<?php
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("$uploadf['path']" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "$uploadf['path']" . $_FILES["file"]["name"]);
      echo "Stored in: " . "$uploadf['path']" . $_FILES["file"]["name"];
      }
    }
?>

 

but there are two problems:

1. doesn't work

2. when i did it i tried echoing $uploadf['path'] and didn't get any return

 

does anyone know how to do this?

 

Oh yeah... also I wanted to do tagging on my news page where i have an array of tags in $tags that's formatted like tag1, tag2... and then explode it using "," then when i echo $tags i wanted to make it so that if you clicked on any of the tags, it would send the tag to a page where i could filter the news stories by the tags. I don't know where to begin this... but i think it'd begin by getting my first question answered. Thanks.

changed that

now i get a

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/hypboard/public_html/thehyp/upload_file.php on line 20

 

which is

 

     "$uploadf['path']".$_FILES["file"]["name"]);

 

tried removing the quotes there, didn't help.

Parse error: syntax error, unexpected '[', expecting ',' or ';' in /home/hypboard/public_html/thehyp/upload_file.php on line 21

 

<?php
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists($uploadf['path'] . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      $uploadf['path'].$_FILES["file"]["name"]);
      echo "Stored in: ".uploadf['path'].$_FILES["file"]["name"];
      }
    }
?>

 

thinking this might end up being something dumb i overlook now

Parse error: syntax error, unexpected '[', expecting ',' or ';' in /home/hypboard/public_html/thehyp/upload_file.php on line 20

 

got rid of line 20 because it was the echo and now i get

 

Upload: watermark.php.jpg

Type: image/jpeg

Size: 58.4677734375 Kb

Temp file: /tmp/phpS4i687

 

Warning: move_uploaded_file(watermark.php.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/hypboard/public_html/thehyp/upload_file.php on line 19

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpS4i687' to 'watermark.php.jpg' in /home/hypboard/public_html/thehyp/upload_file.php on line 19

Stored

 

and the upload form looks like this by the way

<html>
<body>
<?php 
$uploadf = array();
$uploadf['path']="images/media/";
?>

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.