Jump to content

file upload problem: newbie


paulferree

Recommended Posts

Hey guys,

 

I'm new to PHP.  I'm trying to have a file uploaded by a form but I get this error message and I can't figure out why it's not working.  I even copied the exact code from PHPs site.

 

Any help would be appreciated?

 

This is what is produced when the script is run.  (the upload directory is set to 777 BTW)

 

 

Tageted Directory: /uploaded_images/logo.gif

 

Sorry, there was a problem uploading your file.

Array

(

    [uploaded] => Array

        (

            [name] => logo.gif

            [type] => image/gif

            [tmp_name] => /tmp/phpW5dLdq

            [error] => 0

            => 8575

        )

 

)

 

Thanks!

Paulo

 

Link to comment
Share on other sites

Sorry:

 

HERES THE FORM:

<form enctype="multipart/form-data" action="file_uploaded.php" method="POST">

Please choose a file: <input name="uploaded" type="file" /><br />

<input type="submit" value="Upload" />

</form>

 

 

 

HERE'S THE PHP

<?php

$target = "/uploaded_images/";

$target = $target . basename( $_FILES['uploaded']['name']) ;

echo "Tageted Directory: ". $target;

 

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))

{

echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";

}

else {

echo '<pre>';

echo "Sorry, there was a problem uploading your file.</br>";

print_r($_FILES);

echo '</pre>';

}

?>

 

Thanks,

Paul

Link to comment
Share on other sites

Yeah, your target starts with a slash, telling the sever it's an absolute path. I assume you are looking for a relative path (ie the folder uploaded_images is in the same folder as the php script). If that is true, just remove the leading slash:

 

$target = "uploaded_images/";

Link to comment
Share on other sites

here is the PHP with more debug info added, let us know what it outputs now:

 

<?php
  $target = "/uploaded_images/";
  echo "Tageted Directory: {$target}<br>";
  if(!is_dir($target)) die("Dir doesn't exist");
  if(!is_writable($target)) die("Dir is not writable");

  $target = $target . basename( $_FILES['uploaded']['name']);
  echo "Saving to file: {$target}<br>";

  if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){
    echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
  } else {
    echo "Sorry, there was a problem uploading your file.</br>";
    print_r($_FILES);
  }
?>

 

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.