Zeradin Posted July 29, 2008 Share Posted July 29, 2008 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. Link to comment https://forums.phpfreaks.com/topic/117189-making-variables-or-array-elements-into-file-paths-tagging/ Share on other sites More sharing options...
lemmin Posted July 29, 2008 Share Posted July 29, 2008 Get rid of these quotes in this line: if (file_exists("$uploadf['path']" . $_FILES["file"]["name"])) Like this: if (file_exists($uploadf['path'] . $_FILES["file"]["name"])) Link to comment https://forums.phpfreaks.com/topic/117189-making-variables-or-array-elements-into-file-paths-tagging/#findComment-602894 Share on other sites More sharing options...
Zeradin Posted July 29, 2008 Author Share Posted July 29, 2008 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. Link to comment https://forums.phpfreaks.com/topic/117189-making-variables-or-array-elements-into-file-paths-tagging/#findComment-602917 Share on other sites More sharing options...
lemmin Posted July 29, 2008 Share Posted July 29, 2008 You don't need the quotes around it there, either; though I wouldn't think that would cause that error. Take out those quotes and if it doesn't work post the whole code again. Link to comment https://forums.phpfreaks.com/topic/117189-making-variables-or-array-elements-into-file-paths-tagging/#findComment-602932 Share on other sites More sharing options...
Zeradin Posted July 29, 2008 Author Share Posted July 29, 2008 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 Link to comment https://forums.phpfreaks.com/topic/117189-making-variables-or-array-elements-into-file-paths-tagging/#findComment-602970 Share on other sites More sharing options...
lemmin Posted July 29, 2008 Share Posted July 29, 2008 Try changing this: move_uploaded_file($_FILES["file"]["tmp_name"], $uploadf['path'].$_FILES["file"]["name"]); To this: move_uploaded_file($_FILES["file"]["tmp_name"], $uploadf['path'].$_FILES["file"]["name"]); Link to comment https://forums.phpfreaks.com/topic/117189-making-variables-or-array-elements-into-file-paths-tagging/#findComment-603108 Share on other sites More sharing options...
Zeradin Posted July 30, 2008 Author Share Posted July 30, 2008 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> Link to comment https://forums.phpfreaks.com/topic/117189-making-variables-or-array-elements-into-file-paths-tagging/#findComment-603307 Share on other sites More sharing options...
lemmin Posted July 30, 2008 Share Posted July 30, 2008 Your web server doesn't have permission to write to that folder. It should work if you give it permission. Link to comment https://forums.phpfreaks.com/topic/117189-making-variables-or-array-elements-into-file-paths-tagging/#findComment-604071 Share on other sites More sharing options...
ronnie88 Posted July 30, 2008 Share Posted July 30, 2008 sounds like you need to chmod Link to comment https://forums.phpfreaks.com/topic/117189-making-variables-or-array-elements-into-file-paths-tagging/#findComment-604074 Share on other sites More sharing options...
Zeradin Posted July 31, 2008 Author Share Posted July 31, 2008 images/media is chmodded to 777 that's where it's trying to go, no? Link to comment https://forums.phpfreaks.com/topic/117189-making-variables-or-array-elements-into-file-paths-tagging/#findComment-604134 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.