Forum Moderators: coopster
<form method="POST" action="form.php">
<input type="text" name="name">
<input type="text" name="email">
<form method="post" enctype="multipart/form-data" action="upload.php">
<input name="uploadedfile" type="file">
<input type="submit" value="upload" name="submit">
</form>
<input type="hidden" value="<?php echo $filename; ?>" name="filelocation" >
<input type="submit" value="submit" name="submit">
</form>
Obviously this example will not work, I am just wondering what approach to take and what others are doing for this. I've seen some examples that use iframes and ajax.
$path = "/path/to/your/upload/location/";
$file = $_FILES["uploadedfile"]["name"];
$tmpfile = $_FILES["uploadedfile"]["tmp_name"];//upload and give it a random name so no conflicts occur
$rand = mt_rand(1,3000);
$save_path = $path . $rand . $file;
//move the temp file to the proper place
if (move_uploaded_file($tmpfile, $save_path))
//do stuff like enter filename to the db
}
It probably wouldn't be a bad idea to check extensions for allowed types too. This is a function i use for that you can change the file extension to whatever you want.
function checkAllowedExt($file)
{
//check file for allowed extensions returns true if wrong type
$temp = strtolower($file);
$ext_split = split("\.",$temp);
$ext = $ext_split[1];
$allowed = array('gif', 'jpg', 'jpeg', 'png');
if (!in_array($ext, $allowed))
return true;
return false;
}
I hope that gives you an idea
Regards,
Brandon