PDA

View Full Version : upload a file


BroChris
01-21-2006, 11:18 PM
I've got two questions, both relating to an upload form. I've done this many times on many sites, but I can't seem to get it to work on the site I'm currently working on. The folder is set to be writable. I can't think of anything else that's wrong. Is anything wrong with this code, and if not, is there anything else I can check?

Relevant code:
<?php
if($action=="send"){
$picture=$_FILES['picture']['name'];
$path = "images/" . $picture;
move_uploaded_file($_FILES['picture']['tmp_name'], $path);
}
?>

<form action="uploadpicture.php?action=send" method="post">
<input type="file" id="picture" name="picture" maxlength="500">
<input type="submit" value="send">
</form>

My second question has to do with repopulating the file field if another required field was left blank. My typical method (filling the value field with the variable) doesn't seem to work.

Thanks in advance!

Element
01-22-2006, 01:08 AM
try using a absolute path, and put

<?php error_reporting(E_ALL); ?>

at thee top of your document
and you should usee if statements on your functions sometimes if it can return false and is critical to the running of the script.


<?php

error_reporting(E_ALL);

if(isset($_POST['submit'])) {
if(isset($_FILES['picture']['name'])) {
$picture = $_FILES['picture']['name'];
$path = "/home/user/public_html/images/" . $picture;
if(!(move_uploaded_file($_FILES['picture']['tmp_name'], $path))) {
die("Unable to upload image.");
}
} else {
die("You must pick an image to upload first!");
}
}

?>


<form action="uploadpicture.php" method="post" enctype="multipart/form-data">
<input type="file" id="picture" name="picture" maxlength="500">
<input type="submit" name="submit" value="Send">
</form>


you also forgot the encrypt type.