Laravel Dusk Visit method keeps going back to APP_URL - laravel

I have the following on my TimelineTest Dusk file
$browser->visit('/wall/' . $this->username . '/' . $this->userID)
->assertTitleContains($this->username . ' - SiteName');
But although I am specifying the url to visit, my test fails because Dusk still visits the root / and not the url I specified /wall/' . $this->username . '/' . $this->userID
I dumped the current url using
$url = $browser->driver->getCurrentURL();
dd($url);
And it is the correct one, but my assertion fails saying that my title was not found in the page title, which corresponds to the one in the index page /
Did anyone have Dusk not visiting the URL they specified?

Related

Laravel 5.7 + Intervention Image : Image source not readable

I've create an app that upload image along with title, description & etc. However, i'm having a problem in some of the images to upload, it returns an error ("Image source not readable") as shown below:
Here's my Code:
$image = $request->file('image');
// $image = Input::file('image'); // already tried this one still same problem
$orginal_filename = $image->getClientOriginalName();
$ext = $image->getClientOriginalExtension();
$fileName = md5(microtime() . $orginal_filename) . '.' . $ext;
$img = Image::make($image->getRealPath());
$img->stream();
$img->resize(1200, null, function ($constraint) {
$constraint->aspectRatio();
});
Storage::disk('storage_dir')->put($dir . $fileName, $img, 'public');
Already tried following solutions:
Change to Input::file('file')
Check if Request Content-Type has multipart/form-data (Request already has multipart/form-data Content-Type)
Change Intervention Image driver from "gd" to "imagick"
but still have the "Image source not readable" error.
Note: Error only occurs in some images. (I've also tried moving the image(w/c produced the errors) into another directory but still error occurs).
Thank you so much for the help!
You can try running my code
if ($request->file('photo')->isValid()) {
$avatar = $request->file('photo');
$filename = time() . '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300, 300)->save( public_path('/uploads/avatars/' . $filename) );
}
/uploads/avatars/ is my directory
If the problem occours in a Laravel 5.7 project, and you store your pictures in the storage folder, it might solve the problem to enter this into the terminal:
php artisan storage:link
(The problem occurs if you have cloned the project from github og bitbucket)
Sorry for bothering guys! It seemed that it was all my fault not realizing php post_max_size and php upload_max_file_size. Since i was trying to upload an image larger than 8MB i only increased the post_max_size > than the current image file size, but not the upload_max_file_size coz i only increased it by 2 (stated: 4MB).
Thanks btw for the help and suggestions!
Replace
$resize = Image::make('storage/app/public/'.$user->image)->resize(300,300);
with
$resize = Image::make(storage_path('app/public/'.$user->image))->resize(300,300);
Give storage full path will solve the problem.
If you got this error on your server, you need to be sure you pushed the all images to server. You are facing this error because of server could not find or read to image/images.
-> Be sure image/images uploaded
-> Make readable to image/images.

Error while uploading in Laravel 4

I'm trying to make a image upload in lavarel 4. The upload passes by
The file "C:\xampp\tmp\phpD1F3.tmp" does not exist
This is my upload code :
$file = Input::file('image');
// Get extension
$extension =$file->getClientOriginalExtension();
// Generate a file name
$fileName = 'pool' . Str::quickRandom();
$fileNameExtension = $fileName . '.' . $extension;
// Process upload
Input::file('image')->move(public_path() . '/uploads/images/app/pools/original/', $fileNameExtension);
`
I don't know why i get this error , please can anyone help me to solve this?
You are probably making some operations on "uploaded" file after moving it to server by move() function. Please make sure there is no operation made on temporary file after calling Input::file('image')->move() function.

Locking specific cells with a password phpExcel

I am uploading an excel file from a folder in my computer to a folder in the server, after the upload i am loading the uploaded file so that i can protect certain cell, the first method i used below does not work at all
function LockCertainCells(){
$labref= $this->uri->segment(3);
$objReader = new PHPExcel_Reader_Excel2007();
$path = "analyst_uploads/" . date('Y') . '/' . date('M') . '/'. $labref .'/'. $labref . ".xlsx";
$objPHPExcel = $objReader->load($path);
$objPHPExcel->setActiveSheetIndexbyName('Sample Summary');
$objPHPExcel->getActiveSheet()->protectCells('A17:G85','PHPExcel');
$objPHPExcel ->getActiveSheet()->getProtection()->setSheet(true);
}
This second one
function LockCertainCells(){
$labref= $this->uri->segment(3);
$objPHPExcel = new PHPExcel;
$path = "analyst_uploads/" . date('Y') . '/' . date('M') . '/'. $labref .'/'. $labref . ".xlsx";
$objSheet = $objPHPExcel->load($path);
$objSheet->setActiveSheetIndexbyName('Sample Summary');
$objSheet->protectCells('A17:G85', 'PHP');
$objSheet->getProtection()->setSheet(true);
}
Throws me this error:
Fatal error: Call to undefined method PHPExcel::load() in C:\127.0.0.1\htdocs\NQCL\.....
suggestions!
The PHPExcel class doesn't have a load method, which is precisely why you get that error.... the first method is the method provided by the PHPExcel library for loading a file into a PHPExcel object, the second is not. Use the method that works (and is the method described in all the documentation); not the one that doesn't exist.
The first method for locking the cells isn't doing anything with the PHPExcel object (such as saving it) after you have set cell protection; so as soon as the LockCertainCells function terminates, it will be out of scope and discarded by the PHP script. If you want to make the changes in the file, you need to save the file again. I believe that MS Excel itself requires you to save a file if you want to make any changes to that file permanent.
EDIT
You also miss setting the password for the protected cells:
$objSheet->getProtection()->setPassword('mypassword');

Localhost and fopen

We are now working in a local environment, rather than working live, which is a good thing. However, I've run into a hiccup I don't know how to fix. My code (CodeIgniter) looks like this:
if (!is_dir(base_url() . 'channel-partners/html/camera-registration/' . $name_url)) {
mkdir(base_url() . 'channel-partners/html/camera-registration/' . $name_url);
}
$handle = fopen('/path/to/file/channel-partners/html/camera-registration/' . $name_url . '/index.html', 'w') or die('Can\'t open file');
fwrite($handle, $html);
fclose($handle);
But since I'm running MAMP, $_SERVER['DOCUMENT_ROOT'] equals Applications/MAMP/htdocs, so that won't work. So what can I do to write a file in PHP that would work in both a production environment and a local environment?
Use the FCPATH or APPPATH constants.
FCPATH will give you the path to the directory where the front controller is located (index.php).
APPPATH will give you the path to the application directory.
Usage:
fopen(FCPATH . 'path/relative/to/frontcontroller/etc/' . $name_url . '/index.html', 'w') ...

Ajax Post Security Question

so i have a problem, i have this code:
$params = "'plname=" . $player->username . "&plmiss=" . $player->miss . "&plmaxdmg=" . $player->maxdmg . "&plmindmg=" . $player->mindmg . "&plhp=" . $player->hp . "&plmhp=" . $player->maxhp;
$params .= "&enname=" . $enemy->username . "&enmiss=" . $enemy->miss . "&enmaxdmg=" . $enemy->maxdmg . "&enmindmg=" . $enemy->mindmg . "&enhp=" . $enemy->hp . "&enmhp=" . $enemy->hp . "'";
buttonform("pvm.php","Attack",$params);
buttonform function:
function buttonform($page,$texto,$params)
{
?><input type="button" onclick="ajaxpost('menu','<?php echo $page;?>',<?php echo $params;?>);" class="button" value="<?php echo $texto;?>"><?
}
so you guessed it the function will create a button that when be clicked will send an ajax request for the pvm.php + $params.
but the problem is that $params is confidential and should not be avaiable to change. but if we enter in the page code (ive done this with google chrome developer tools) we can change those variables to what we want, and that is what i dont want. if anyone can help me to make those variables not avaiable for change, THANKYOU!
Anything loaded into the user's browser is available for change. You'll have to store that information server-side.
To that end, take a look at PHP sessions:
http://www.w3schools.com/PHP/php_sessions.asp
http://www.php.net/manual/en/book.session.php

Resources