No such table exists php POST file - php

I am receiving a file via (sqlite file) and trying to connect to it using sqlite3. I tested this all using a sqlite file that was already on there on the server but now that im trying to do it when it gets uploaded I am trying to do operations to it.
I am getting the error that not table exists but I know it does because i open it sqlite manager and verify it is there. here is a snippet of code
$folder = '/var/www/uploads/';
if ( !file_exists($folder) ) {
mkdir ($folder, 0777);
}
$uploadfile = $folder.rand(). '-'. basename($_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
$db = new SQLite3($uploadfile);
if ($db->lastErrorMsg() != 'not an error') {
print "Database Error: " . $db->lastErrorMsg() . "<br />";
}
$sql ="SELECT * FROM projects";
$result = $db->query($sql);
if ($db->lastErrorMsg() != 'not an error') {
print "Database Error: " . $db->lastErrorMsg() . "<br />";
}
this is my error
/var/www/uploads/79316479-db.sqlite
Database Error: no such table: projects

Related

Imagejpeg returns false but file exists

Yesterday I got an output imagejpg() (albeit unreadable character because I havent set the header) but today nothing. The only thing I can that I changed is enabling special permissions on the server. Any idea what else could have affected it? The output for the following code is:
The file exists
Imagejpeg: FALSE
Imagejpeg: FALSE
The file is writable
The output is the same if $filename = $URL.
The code:
clearstatcache();
$filename = $_SERVER['DOCUMENT_ROOT'] . "/wordpress/wp-content/themes/mytheme/images/thumbnails/sb1778/1.jpg";
$URL = get_template_directory_uri() . "/images/thumbnails/sb1778/1.jpg";
if (file_exists($filename)) {
echo "<BR> The file exists";
} else {
echo "<BR> The file does NOT exist";
}
if((imagejpeg($filename)) === true)
{echo "<BR> Imagejpeg: TRUE";}
else {echo "<BR> Imagejpeg: FALSE";}
imagejpeg($filename);
if((imagejpeg($URL)) === true)
{echo "<BR> Imagejpeg: TRUE";}
else {echo "<BR> Imagejpeg: FALSE";}
imagejpeg($URL);
if (is_writable($filename )) {
echo '<BR> The file is writable';
} else { echo '<BR> The file is NOT writable';
}
The image needs to go through the Imagescreatefromjpeg function first:
$filename = imagecreatefromjpeg($_SERVER['DOCUMENT_ROOT'] . "/wordpress/wp-content/themes/mytheme/images/thumbnails/sb1778/1.jpg");

PHP move_uploaded_file is not working

I am not sure what is wrong here but I know it has to do with move_uploaded_file. I have tried changing the name that the file gets changed to and I have changed the chmod of the directory to 777. From what I can tell there is no reason why the file isn't getting moved, but it isn't.
Here is the code in question. Keep in mind this is part of a Wordpress plugin, so I use functions from there in my code.
if ( isset($_FILES["file"])) {
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"];
die;
} else {
if (file_exists("upload/" . $_FILES["file"]["name"])) {
echo $_FILES["file"]["name"] . " already exists. ";
die;
} elseif(strtolower(end(explode('.', $_FILES['file']['name']))) != "csv") {
echo "File is not a .csv";
die;
} else {
if(move_uploaded_file($_FILES["file"]["tmp_name"], plugin_dir_path( __FILE__ ) . "uploads/uploaded_file.csv")) {
echo "Stored in: " . plugin_dir_path( __FILE__ ) . "upload/uploaded_file.csv<br />";
} else {
echo "Temp file was not moved.<br />";
echo '<pre>';
echo 'Here is some more debugging info:<br />';
print_r($_FILES);
print "</pre>";
}
}
}
echo '<form method="post" action="" enctype="multipart/form-data">';
echo '<input type="file" name="file" id="file" />';
submit_button('Import CSV');
echo '</form>';
In the same situation i used: $name = basename($_FILES["file"]["name"]); before calling move_uploaded_file(), i'm not saying it's the solution but maybe you are repeating the path.
Hope it helps.

unable to insert the data values using pdo in PHP

Hello I have been writing a code for uploading a file to server
and store the values on the Mysql database
I am able to upload the file but facing issues in inserting the values in MYSQL server
I'm retrieving the values from an HTML Form and I'm successfully able to get the values and was able to echo from the file
Help is needed in inserting into table part of the code
<?php
require "test.php";
$username=$_POST['username'];
$filename=$_FILES['uploadedfile']['name'];
$language=$_POST['language'];
$comment=$_POST['comment'];
$user_id=$_POST['user_id'];
$filenames=$_FILES['uploadedfile']['name'];
$category=$_POST['category'];
$subcategory=$_POST['subcategory'];
$comment=$_POST['comment'];
$language=$_POST['language'];
$duration=$_POST['duration'];
$domain ='example.com/store/upload/';
$path=$domain.$category.'/'.$filenames;
//$path=$domain.$category.'/'.$filenames;
// Where the file is going to be placed
$target_path = "upload/".$category.'/';
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$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!";
echo "filename: " . basename( $_FILES['uploadedfile']['name']);
echo "target_path: " .$target_path;
}
echo $filenames."<br />";
echo $domain."<br />";
echo $category."<br />";
echo $path."<br />";
echo $filename."<br />";
echo $language."<br />";
echo $comment."<br />";
echo $subcategory."<br />";
echo $duration."<br />";
echo $user_id."<br />";
// query
try{
$sql="INSERT INTO vup_file(filename,path,category,sub-category,user_id,comment,language,duration)
VALUES (:filename,:path,:category,:subcategory,:user_id,:comment,:language,:duration)";
$query=$conn->prepare($sql);
$query->execute(array(':filename'=>$filename,':path'=>$path,':category'=>$category,':subcategory'=>$subcategory,':user_id'=>$user_id,':comment'=>$comment,':language'=>$language,':duration'=>$duration));
echo 'Inserted';
}catch(PDOException $e)
{
echo 'ERROR OCCURED : '.$e->getMessage();
}
?>
Your sub-category column in your query, contains a hyphen. It needs to be escaped with backticks.
`sub-category`
Add $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); right after the connection is opened, which would have signaled the error.
SQL is evaluating it as a mathematical problem (minus).
Which translates to "sub" minus "category".
Another option you have is to simply rename your column to sub_category with an underscore, without the need to escape it.
An insight
If by chance your column is called sub_category instead of sub-category as shown in your query/question, then you will need to change it to sub_category in your query.
Or, if it's called subcategory. Only you know what your column is called.

PHP copying files from one location to the other

not working with mp3 files ,,, working fine with text and image files
if(isset($_POST["submit"]))
{
echo "<br><br>user file uploading</br></br>";
echo "Name : <font color='green'>".$_FILES["userfile"]["name"]."</font>";
echo "<br><br>";
echo "Type :<font color='green'>".$_FILES['userfile']['type']."</font>";
echo "<br><br>";
echo "Size :<font color='green'>".($_FILES['userfile']['size']/1024)."</font>";
echo "<br><br>";
if (file_exists("G:/" . $_FILES["userfile"]["name"]))
{
echo "<font color='red'>".$_FILES["userfile"]["name"] . " already exists. </font>";
}
else {
move_uploaded_file($_FILES["userfile"]["tmp_name"],"G:/" . $_FILES["userfile"]["name"]);
echo "<font color='blue'>Stored in: " . "G:/" . $_FILES["userfile"]["name"]."</font>";
}
}
The MP3 files are too big. The list of error codes can be found here. For 1 it says:
UPLOAD_ERR_INI_SIZE
Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
Increase the setting in php.ini to allow bigger files to be uploaded.

Echo "success" after using ftp_put()

I have a php script that sends large files via FTP. After the file is sent I'm trying to write to the browser "success". I'm also trying to send a query to the database to record that the file was sent. However, any code that I have that comes after the ftp_put does not get executed.
if (ftp_put($conn_id, $upload_filename, $filename, FTP_BINARY))
{
echo "File Sent";
echo $upload_filename." - ".date("d/m/Y H:i:s")." - ".filesize($filename)." bytes<br>" ;
}
else
{
echo "Problem while Uploading $filename\n <br/>". $upload_filename ;
}
If ftp_put is false the echo works. But, if the ftp_put is a success any code I put there will not run.
The file size I am sending is 7,305kb
It is likely that the problem here is that your script is timing out while the file is uploading. Try adding this line before the code above:
set_time_limit(0);
The thing is that ftp_put() blocks any further action until the upload is finished. Try ftp_nb_put() (no blocking) like so:
$upload = ftp_nb_put($conn_id, $upload_filename, $filename, FTP_BINARY);
if($upload == FTP_MOREDATA)
{
echo 'Uploading ' . $upload_filename . ' - ' . date("d/m/Y H:i:s") . ' - ' . filesize($filename) . ' bytes<br />';
while($upload == FTP_MOREDATA)
{
echo '.'; //Output a . to page or do whatever
$upload = ftp_nb_continue($conn_id);
}
}
//Note: While in the while above, it will either end in FTP_FINISHED or FTP_FAILED
if($upload == FTP_FAILED)
{
echo "Problem while Uploading $filename\n <br />". $upload_filename;
}

Categories