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
https://forums.phpfreaks.com/topic/91088-file-upload-problem-newbie/
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

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/";

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);
  }
?>

 

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.