ultimachris Posted April 14, 2009 Share Posted April 14, 2009 Hi all, this is the php script im using so users can upload an image to my server, but for some reason i get a T_string error Parse error: syntax error, unexpected T_STRING, expecting ']' in /home/vol5/byethost14.com/b14_3115753/htdocs/urbantickets/do_upload.php on line 5 This is the script: <?php $file_dir = "htdocs/urbantickets/widgetimg"; $file_url = "http://ultimasandbox.byethost14.com/urbantickets/widgetimg"; foreach($_FILES as $file_name => $file_array) { echo "path: ".$file_array['"tmp_'name"]."<br />\n"; echo "name: ".$file_array[''"name"]."<br />\n"; echo "type: ".$file_array["'type'"]."<br />\n"; echo "size: ".$file_array[''"size"]."<br />\n"; if (is_uploaded_file($file_array['"tmp_'name"])) { move_uploaded_file($file_array['"tmp_'name"], "$file_dir/".$file_array["name"]") or die ("couldnt copy"); echo "file was moved!<br />"; } } ?> and this is the HTML: <form enctype="multipart/form-data" action="do_upload.php" method="POST"> Please choose a file: <input name="uploaded" type="file" /><br /> <input type="submit" value="Upload" /> </form> Does anyone know what im doing wrong? i know this is a simple newbie error, im so ashamed! Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 change it to this... <?php $file_dir = "htdocs/urbantickets/widgetimg"; $file_url = "http://ultimasandbox.byethost14.com/urbantickets/widgetimg"; foreach($_FILES as $file_name => $file_array) { echo "path: ".$file_array["tmp_name"]."<br />\n"; echo "name: ".$file_array["name"]."<br />\n"; echo "type: ".$file_array["type"]."<br />\n"; echo "size: ".$file_array["size"]."<br />\n"; if (is_uploaded_file($file_array["tmp_name"])) { move_uploaded_file($file_array["tmp_name"],$file_dir."/".$file_array["name"]) or die ("couldnt copy"); echo "file was moved!<br />"; } } ?> you have extra quotes in $file_array Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 14, 2009 Share Posted April 14, 2009 2 Things: 1. Use the code /code bbcodes around your code. 2. You need to read about and understand the difference between ' and " and how it relates to string variables, interpolation and array elements. Your error was obvious and trivial. Quote Link to comment Share on other sites More sharing options...
ultimachris Posted April 14, 2009 Author Share Posted April 14, 2009 thanks to both of you, im still getting errors : Warning: move_uploaded_file() [function.move-uploaded-file]: URL file-access is disabled in the server configuration in /home/vol5/byethost14.com/b14_3115753/htdocs/urbantickets/do_upload.php on line 10 Warning: move_uploaded_file(http://ultimasandbox.byethost14.com/urbantickets/widgetimg/skyrocketpagerank.gif) [function.move-uploaded-file]: failed to open stream: no suitable wrapper could be found in /home/vol5/byethost14.com/b14_3115753/htdocs/urbantickets/do_upload.php on line 10 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpoQuqp1' to 'http://ultimasandbox.byethost14.com/urbantickets/widgetimg/skyrocketpagerank.gif' in /home/vol5/byethost14.com/b14_3115753/htdocs/urbantickets/do_upload.php on line 10 couldnt copy I believe the first is because i have to make the folder on the server a "write to" folder so it can be accessed? but im not sure if the other errors point also to this problem.... Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 I'm not completely sure, but I do think the folder permissions need to be changed abit. Quote Link to comment Share on other sites More sharing options...
ultimachris Posted April 14, 2009 Author Share Posted April 14, 2009 ive chmoded widgetimg to 777. ....still nothing.... Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 sorry I'm not familiar with move_uploaded_file(); , not entirely sure what the errors mean. I'll take a stab in the dark through... this error... Warning: move_uploaded_file() [function.move-uploaded-file]: URL file-access is disabled in the server configuration I'm guessing if you specify the direct path to where you want it to go rather then the URL it may work. Warning: move_uploaded_file(http://ultimasandbox.byethost14.com/urbantickets/widgetimg/skyrocketpagerank.gif) [function.move-uploaded-file]: failed to open stream: no suitable wrapper could be found in $file_array["tmp_name"] may not contain the value you think it does? Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move Maybe the file doesn't exist? Quote Link to comment Share on other sites More sharing options...
ultimachris Posted April 14, 2009 Author Share Posted April 14, 2009 Hi Master ace. ive tried to assign both the file_dir and file_url variables to this: <?php $file_dir = "/htdocs/urbantickets/widgetimg/"; $file_url = "http://ultimasandbox.byethost14.com/urbantickets/widgetimg"; foreach($_FILES as $file_name => $file_array) { echo "path: ".$file_array["tmp_name"]."<br />\n"; echo "name: ".$file_array["name"]."<br />\n"; echo "type: ".$file_array["type"]."<br />\n"; echo "size: ".$file_array["size"]."<br />\n"; if (is_uploaded_file($file_array["tmp_name"])) { move_uploaded_file($file_array["tmp_name"],$file_dir."/".$file_array["name"]) or die ("couldnt copy"); echo "file was moved!<br />"; } } ?> I no longer get the URL permissions errors but get these 2: Warning: move_uploaded_file(/htdocs/urbantickets/widgetimg//skyrocketpagerank.gif) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/vol5/byethost14.com/b14_3115753/htdocs/urbantickets/do_upload.php on line 11 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpQZWDUt' to '/htdocs/urbantickets/widgetimg//skyrocketpagerank.gif' in /home/vol5/byethost14.com/b14_3115753/htdocs/urbantickets/do_upload.php on line 11 couldnt copy How does PHP generate this path code: '/tmp/phpQZWDUt' - ? Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 14, 2009 Share Posted April 14, 2009 The error is pretty much telling you what is wrong. Your destination path/filename is a url for some reason. It doesn't appear you've provided the code you are using, as it looks as if you somehow are injecting a url into the destination parameter when it should be a simple path and filename on your server. What is the code you are using right now? Quote Link to comment Share on other sites More sharing options...
ultimachris Posted April 14, 2009 Author Share Posted April 14, 2009 Hi Gizmola, the html is simply: <form enctype="multipart/form-data" action="do_upload.php" method="POST"> Please choose a file: <input name="uploaded" type="file" /><br /> <input type="submit" value="Upload" /> </form> and do_upload.php is: <?php $file_dir = "/htdocs/urbantickets/widgetimg/"; $file_url = "http://ultimasandbox.byethost14.com/urbantickets/widgetimg"; foreach($_FILES as $file_name => $file_array) { echo "path: ".$file_array["tmp_name"]."<br />\n"; echo "name: ".$file_array["name"]."<br />\n"; echo "type: ".$file_array["type"]."<br />\n"; echo "size: ".$file_array["size"]."<br />\n"; if (is_uploaded_file($file_array["tmp_name"])) { move_uploaded_file($file_array["tmp_name"],$file_dir."/".$file_array["name"]) or die ("couldnt copy"); echo "file was moved!<br />"; } } ?> i know what you mean with the URL is basically pointing at the php file, but im a bit stumped on how to change it. i know $file_dir and $file_url are correct. Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 14, 2009 Share Posted April 14, 2009 ultimachris --- If you really want help, you need to read what is being written to you. At the top of these posts I asked you to use the code tags around your code. I inserted them in your original post, but I don't want to keep doing that. To answer your question, where PHP sticks temporary files is a function of the php configuration done in the php.ini file. In your case it is using the /tmp directory on the server. From there, PHP will simply create a random file name, to obscure what is going on. You really don't need to be concerned about that. It is not the current problem. The current problem is either that the path is invalid: /htdocs/urbantickets/widgetimg/ or it doesn't like your extra / in the path: /htdocs/urbantickets/widgetimg//skyrocketpagerank.gif If you look at your code, you can fix this either in the url variable or by omitting the extra "/" you concat on there. Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 14, 2009 Share Posted April 14, 2009 Also -- $file_url variable is not being used *now*. Obviously it was being used before, incorrectly. I don't know what you are planning to do with that variable, but at least you stopped using it for now. Quote Link to comment Share on other sites More sharing options...
ultimachris Posted April 14, 2009 Author Share Posted April 14, 2009 thanks Gizmola. Quote Link to comment Share on other sites More sharing options...
ultimachris Posted April 14, 2009 Author Share Posted April 14, 2009 ive removed the $file_url variable, and the additional / that is generated but im convinced the FTP path of: /htdocs/urbantickets/widgetimg is accurate, this is what it states in fireFTP but i still get these errors....its depressing!!!! Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 15, 2009 Share Posted April 15, 2009 FTP paths can be chrooted as well. Is that the *real* path on the server? phpinfo() is a good tool for checking these things if you don't have access to a shell, but of course the shell is ideal. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.