View Full Version : PHP Form Upload Pt. 2


AcidMan00Agent
06-12-2006, 01:05 PM
Here is a shorter version.. that didn't work alone..

I spliced the two pieces together .. rather shoddy-like. Post 3 will have the combined.


<?php
// Where the file is going to be placed
$target_path = "uploads/";

/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name'];
$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>


I am also trying to read all the picture files in a certain directory and then post them to a page as actual images. I have this as a base code, but everything I have tried ... either errors out or prints the names of the files..

<?php
$dir = "uploads/";
function read_dir($dir) {
$path = opendir($dir);
while (false !== ($file = readdir($path))) {
if($file!="." && $file!="..") {
if(is_file($dir."/".$file))
$files[]=$file;
else
$dirs[]=$dir."/".$file;
}
}
if($dirs) {
natcasesort($dirs);
foreach($dirs as $dir) {
echo $dir;
read_dir($dir);
}
}
if($files) {
natcasesort($files);
foreach ($files as $file)
echo $dir . $file . "<br>";
}
closedir($path);
}
?>

<?php
$path="uploads/";
read_dir($path);
?>