Closed xkpx64 closed 3 years ago
The example of usage is in tests/via-http folder. It doesn't have download.php. Sorry but that is nothing related to this class.
To get uploaded data, you have to call to getUploadedData()
method. It is already shown in repository's readme ( https://github.com/Rundiz/upload ).
You have to try access those uploaded data without anything update/insert to DB to understand that what each data is. But they are already explained in readme either.
I can't know what you want to use because each array key from getUploadedData()
method is different, you have to play with it and understand what you really need before continue on your work.
I just wanted to do something like this from vfileup $sql = "insert into table (file_upload, file_size, file_type) VALUES ('".$upload_path."/".$data['file_name']."', ".$data['file_size'].", '".$data['file_type']."')";
I find something that shows but i dont know how good it is. for ($i=0; $i < count($uploaded_data); $i++) { $name =$uploaded_data[$i]['name']; $size =$uploaded_data[$i]['size']; echo $name; echo $size; //mysqli_query($conn,"INSERT INTO files (name, size) VALUES ($name,$size)"); }
getUploadedData()
The data from getUploadedData()
method contains array. Each array contain 7 keys (as version 2.x).
name
The file name with extension where its name and extension is the original name that user selected a file. This contains the original name before renamed.extension
The file extension of uploaded file without dot.size
File size in byte.new_name
If you set the option that change the file name whether it is web_safe_file_name
or manually set new_file_name
, this result will be the file name and extension that was renamed. Otherwise it will be the same result as name
.full_path_new_name
Full path to uploaded file.mime
The uploaded file mime type that was detected using finfo()
class.md5_file
The md5 hash of file content using php md5_file()
function.I assume that you want full_path_new_name
for fpath
column, new_name
for fname
column, size
for fsize
column.
Then you can do this...
$uploadedData = $Upload->getUploadedData();
if (is_array($uploadedData)) {
foreach ($uploadedData as $index => $item) {
$sql = 'INSERT INTO `files` (`fname`, `fsize`, `fpath`) VALUES (:name, :size, :path)';
// debug to make sure that your sql statement is correct.
$sql = str_replace(':name', $item['new_name'], $sql);// replace for debug only.
$sql = str_replace(':size', $item['size'], $sql);// replace for debug only.
$sql = str_replace(':path', $item['full_path_new_name'], $sql);// replace for debug only.
echo $sql . '<br>' . PHP_EOL;
// I suggest do not un-comment the code below until you sure that it is correct.
//$stmt= $link->prepare($sql);
// your insert code.
}
unset($index, $item);// free memory.
}
You maybe use your for..loop style. That's looking good, it should run with no problem.
God bless you Sir!
Hello i'am glad that i find that awesome class to upload files, it Works Awesome. I'am developing school site for uploading files, but we need to make when user send file to upload in on database by category. Can you show me some example how to use it. And if possible how to make download.php func or something
I try some query but its not working i dont know how to get proper variables to insert them into db
$data = [ 'name' => //$handle->file_dst_name, $uploaded_data['full_path_new_name'], 'size' => //$handle->file_src_size, 'path' => //$handle->file_dst_pathname,
]; $sql = "INSERT INTO files (fname, fsize, fpath) VALUES (:name, :size, :path)"; $stmt= $link->prepare($sql); if ($stmt->execute($data)) { echo '
Inserted in Database.
'; } else { echo 'Database query failure
'; }