Jump to content

cant upload image file


ultimachris

Recommended Posts

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!

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

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' - ?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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