my data is not updating on online server .the data is updating on local - xpath-1.0

<?php include('../include/config.php');
if(empty($_SESSION['sus']) && empty($_SESSION['spa']))
{
echo "<script>window.location='index.php'</script>";
}
/*##########################################*/
$id=$_GET['id'];
if(isset($_POST['save']))
{
define ("MAX_SIZE","1000");
function getExtension($str)
{
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$errors=0;
$image=$_FILES['image']['name'];
if ($image)
{
$filename = stripslashes($_FILES['image']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")
&& ($extension != "gif")&& ($extension != "JPG") && ($extension != "JPEG")
&& ($extension != "PNG") && ($extension != "GIF"))
{
echo '<h3>Unknown extension!</h3>';
$errors=1;
}
else
{
$size=filesize($_FILES['image']['tmp_name']);
if ($size > MAX_SIZE*1024)
{
echo '<h4>You have exceeded the size limit!</h4>';
$errors=1;
}
$image_name=time().'.'.$extension;
$newname="img/".$image_name;
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<h3>Copy unsuccessfull!</h3>';
$errors=1;
}
else //echo '<h3>uploaded successfull!</h3>';
$title=$_POST['title'];
$content=$_POST['content'];
$sql="update home set title='$title',content='$content',img='$newname' where id='$id'";
$res=mysql_query($sql);
if($res)
{
echo "<script>alert('You have successfully Uploaded')</script>";
echo "<script>window.location='admin_home.php'</script>";
}
else{
echo "failed submit";
echo "<script>window.location='admin_home.php'</script>";
}
}
}
}
?>
actully i updating code on local host it is updating but in online server it is not updating how to update the code
actully i updating code on local host it is updating but in online server it is not updating how to update the code
actully i updating code on local host it is updating but in online server it is not updating how to update the code

What error code do you get?
echo $_FILES['image']['error']
0 => 'There is no error, the file uploaded with success'
1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini'
2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'
3 => 'The uploaded file was only partially uploaded'
4 => 'No file was uploaded'
6 => 'Missing a temporary folder'
7 => 'Failed to write file to disk.'
8 => 'A PHP extension stopped the file upload.'

Related

Streaming a file from remote S3 to react client through rails API

The app already does this using Zipline and allowing to stream one zip file with all the files selected. But what I want to accomplish is that if only one file is being sent achieve the same behavior but instead of sending a compressed zip file sending the file as it is in S3 (with its respective extension such as docx, jpeg, xlsx, etc). So this is what I have so far.
controller
def to_zip_or_single
if params[:attachments].present?
fileNames = {}
files = Attachment.where(id: params[:attachments]
.split(','))
.map do |attachment|
file = attachment.is_image? ? AbstractFileStruct.new(attachment.upload_annotated) : attachment.upload
if !fileNames[attachment.name]
fileNames[attachment.name] = 0
else
fileNames[attachment.name] += 1
end
attachmentName = File.basename(attachment.name, File.extname(attachment.name))
attachmentName = if fileNames[attachment.name] > 0
attachmentName + " (#{fileNames[attachment.name]})" + File.extname(attachment.name)
else
attachmentName + File.extname(attachment.name)
end
[file, attachmentName]
end
end
filename = params[:filename].present? ? params[:filename] : 'attachments.zip'
if files.one?
headers['Content-Disposition'] = 'attachment; filename="' + files[0][1] + '"'
headers['Content-Type'] = 'application/octet-stream'
response.headers['Last-Modified'] = Time.now.httpdate
response.cache_control[:public] ||= false
response.sending_file = true
file = normalize(files[0][0])
the_remote_uri = URI(file[:url])
Net::HTTP.get_response(the_remote_uri) do |response|
# DO SOMETHING WITH THE RESPONSE
end
elsif files
zipline(files, filename)
end
end
def normalize(file)
file = file.file if defined?(CarrierWave::Uploader::Base) && file.is_a?(CarrierWave::Uploader::Base)
if defined?(Paperclip) && file.is_a?(Paperclip::Attachment)
if file.options[:storage] == :filesystem
{ file: File.open(file.path) }
else
{ url: file.expiring_url }
end
elsif defined?(CarrierWave::Storage::Fog::File) && file.is_a?(CarrierWave::Storage::Fog::File)
{ url: file.url }
elsif defined?(CarrierWave::SanitizedFile) && file.is_a?(CarrierWave::SanitizedFile)
{ file: File.open(file.path) }
elsif is_io?(file)
{ file: file }
elsif defined?(ActiveStorage::Blob) && file.is_a?(ActiveStorage::Blob)
{ blob: file }
elsif is_active_storage_attachment?(file) || is_active_storage_one?(file)
{ blob: file.blob }
elsif file.respond_to? :url
{ url: file.url }
elsif file.respond_to? :path
{ file: File.open(file.path) }
elsif file.respond_to? :file
{ file: File.open(file.file) }
elsif is_url?(file)
{ url: file }
else
raise(ArgumentError, 'Bad File/Stream')
end
end
I am a complete noobie to Rails and ruby. What I ultimately want is to be able to download the file from a react client using something like this
axios({
url: path,
method: 'GET',
responseType: 'blob',
}).then( async (response) => {
const fileHandle = await window.showSaveFilePicker({suggestedName: "download", types: [{accept: {"application/octet-stream":[".docx"]}}]});
const writable = await fileHandle.createWritable();
await writable.write( response.data );
await writable.close();
})
I am also not familiarized on how to work with files that good. I understand I have to use something like a writter and stream the file by chunks. I have tried some code such as
open 'large_file', 'w' do |io|
response.read_body do |chunk|
io.write chunk
end
end
and
response.read_body do |chunk|
chunk
end
But none of those have worked. If anyone could point me in the right direction or give me some ideas of what could I try in this scenario I would appreciate a lot
UPDATE
I have tried the following approach
Net::HTTP.get_response(the_remote_uri) do |response|
reader.close
open 'large_file', 'w' do |_io|
response.read_body do |chunk|
toWrite = chunk.force_encoding('UTF-8')
writer.write(toWrite)
end
end
end
But it gives me this error
<Errno::EPIPE: Broken pipe>
Something as simple as this worked for now, I dont think I am streaming the response
but still it does work, hopefully it will work with large files as well
Net::HTTP.get_response(the_remote_uri) do |resp|
self.response_body = resp.read_body
end

Can new customers be created in QBO API Sandbox

If I create a customer with DisplayName other than "Bob-Smith" it gives an error: Unknown class Customer. Using v3-php-sdk
Fatal error: Uncaught Error: Class 'Customer' not found in /home/novaacoustics/public_html/inc/common.php:2247 Stack trace: #0 /home/novaacoustics/public_html/admin/projects/testQuickbooks.php(52): getCustomerObj(Object(QuickBooksOnline\API\DataService\DataService), 'Peter Sutcliffe') #1 {main} thrown in /home/novaacoustics/public_html/inc/common.php on line 2247
Customer is created fine if I use API Explorer. I already know the new customer doesn't yet exist because the query:
$customerArray = $dataService->Query("select * from Customer where DisplayName='" . $customerName . "'");
returns null.
$realmId = $accessTokenObj->setRealmId('4620816365164449490');
$dataService->updateOAuth2Token($accessTokenObj);
$customerRef = getCustomerObj($dataService, "John Smith");
function getCustomerObj($dataService, $customerName = NULL) {
// $customerName = 'Bob-Smith';
$customerArray = $dataService->Query("select * from Customer where DisplayName='" . $customerName . "'");
$error = $dataService->getLastError();
if ($error) {
logError($error);
} else {
if (is_array($customerArray) && sizeof($customerArray) > 0) {
return current($customerArray);
}
}
// Create Customer
echo "creating customer " .$customerName . getGUID();
$customerRequestObj = Customer::create([
"DisplayName" => $customerName . getGUID()
]);
$customerResponseObj = $dataService->Add($customerRequestObj);
$error = $dataService->getLastError();
if ($error) {
logError($error);
} else {
echo "Created Customer with Id={$customerResponseObj->Id}.\n\n";
return $customerResponseObj;
}
}
The getGUID() I tried removing and same error. Also the refresh_ and access_tokens are fine, OAuth2 working great.
OK solved by adding use QuickBooksOnline\API\Facades\Customer; at top of file where getCustomerObj function is.

phpinfo to check server configuration

I would like to ask how to check server configuration (CPU, system, RAM) by "grep" phpinfo sub-information (or any other php commands), if any.
<? if (phpinfo system info == "something A"
&& phpinfo CPU info == "something B"
&& phpinfo RAM info == "something C") {
//Redirect to index.php and not allowed to access in-pages.
header('Location: index.php');
}
?>
// Get CPU name
$cpuinfo = file('/proc/cpuinfo');
$cpu = substr($cpuinfo[4],13);
// Get memory size
$meminfo = file('/proc/meminfo');
$memsize = substr($meminfo[0],10);
// Get IP address
$arp = file('/proc/net/arp');
$arp1 = explode(" ", $arp[1]);
$ipv4 = $arp1[0];
if (strpos($ipv4,[your device ip address]) !== false
&& strpos($memsize,[your device memory size]) !== false
&& strpos($cpu,[your device CPU name]) !== false) {
// go
}

How to validate url in php to avoid continue .. and ::

How to validate url in php to avoid continue .. and ::
For ex:
http::/www.gmail.com
or
http://www.gmail.com
or
http://www.gmail.com.....
Use PHP filter:
$url = "http://google.com";
if (filter_var($url, FILTER_VALIDATE_URL)) {
echo "URL is OK";
}
else {
echo "URL is invalid";
}

AWK-Printing a line as the first record in an output file

Heres the problem:
I have an AWK script which is scheduled to run every day via a crontab entry. This particular script outputs errors to an error log. I have a variable which increments every time an error is encountered and have the following control statement at the end of my script:
if (blErrorCounter) {
print "Log contains " blErrorCounter " errors!"
} else {
print "Log contains no errors!"
}
The script contains a number of other error handling conditions which output data to the log file, but I want to be able to print the above as the very first record in the file...
It maybe something simple as I'm a noob to AWK but any help/pointer would be greatly received.
Shaw
You need to save the error messages to print in the END section, e.g.:
/error/ { errors[++blErrorCounter] = "Got error at line " FNR }
END {
if (blErrorCounter) {
print "Log contains", blErrorCounter, "errors!"
for (ec=1; ec <= blErrorCounter; ec++) {
print errors[ec]
}
} else {
print "Log contains no errors!"
}
}
You could write that a bit briefer too:
/error/ { errors[++blErrorCounter] = "Got error at line " FNR }
END {
print "Log contains", (blErrorCounter ? blErrorCounter : "no"), "errors!"
for (ec=1; ec <= blErrorCounter; ec++) {
print errors[ec]
}
}
Or even just live with "0" instead of the word "no":
/error/ { errors[++blErrorCounter] = "Got error at line " FNR }
END {
printf "Log contains %d errors!\n", blErrorCounter
for (ec=1; ec <= blErrorCounter; ec++) {
print errors[ec]
}
}

Resources