My file isn't being moved to the specified and newly created folder using mkdir - mkdir

So I'm having an issue. When someone signs up for an account on the site I'm building, they go to a setup page where they can upload a profile picture. I'm using mkdir to auto create a sub-folder with their username which is working fine, and CHMOD is 777 on that sub folder. The problem I'm having is that image is not being moved to that specified sub-folder, but it's going into the "uploads" folder which is it's parent directory.
Hopefully I haven't confused anyone, but I'm really needing help.
Below is my script I wrote to do this.
===============================================================================
require_once('../admin/includes/config.php');
$uploaded_file = $_REQUEST['uploaded_file'];
$member_id = $_REQUEST['member_id'];
$name = $_REQUEST['name'];
$location = $_REQUEST['location'];
$hobbies = $_REQUEST['hobbies'];
$hobby = $_REQUEST['hobby'];
// using member_id, extract the username from the members table so we can auto create a sub-directory for the images
$result = mysql_query("SELECT username FROM members WHERE member_id = '$member_id'");
while($row = mysql_fetch_array($result))
{
$username = $row['username'];
}
// unmask to change CHMOD of newly created sub directory to 777
$old_mask = umask(0);
//Create directory with member's username
$madedir = mkdir('../admin/uploads/'.$username.'', 0777) /*== TRUE ? 1 : 0*/;
umask($old_mask);
// Assign the directory the file is going to be uploaded to
$uploaddir = '../admin/uploads/'.$username.'';
// Get the file name
$file_name = $_FILES['uploaded_file']['name'];
// Upload file to assigned directory with file name
$uploadfile = $uploaddir . basename($_FILES['uploaded_file']['name']);
// If the file has been uploaded, run this script
if (move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $uploadfile)) {
echo "Success";
} // end if
else {
echo "there was an error uploading your file";
}

You seem to be missing a / at the end of the upload directory. Change this:
$uploaddir = '../admin/uploads/'.$username.'';
to this:
$uploaddir = '../admin/uploads/'.$username.'/';

Related

laravel 7 pdf-to-text | Could not read pdf file

I installed this laravel package to convert pdf file into text. https://github.com/spatie/pdf-to-text
I'm getting this error:
Could not read sample_1610656868.pdf
I tried passing the file statically by putting it in public folder and by giving path of uploaded file.
Here's my controller:
public function pdftotext(Request $request)
{
if($request->hasFile('file'))
{
// Get the file with extension
$filenameWithExt = $request->file('file')->getClientOriginalName();
//Get the file name
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
//Get the ext
$extension = $request->file('file')->getClientOriginalExtension();
//File name to store
$fileNameToStore = $filename.'_'.time().'.'.$extension;
//Upload File
$path = $request->file('file')->storeAS('public/ebutifier/pdf', $fileNameToStore);
}
// dd($path);
$location = public_path($path);
// $pdf = $request->input('file');
// dd($location);
// echo Pdf::getText($location, 'usr/bin/pdftotext');
$text = (new Pdf('public/ebutifier/pdf/'))
->setPdf($fileNameToStore)
->text();
return $text;
}
Not sure why it's not working any help would be appreciated.
You used spatie/pdf-to-text Package.
I also tried to use this package but it gave me this kind of error.
So, I used asika/pdf2text package and it worked properly
Asika/pdf2text pacakge
And this is my code
$path = public_path('/uploads/documents/'. $file_name);
$reader = new \Asika\Pdf2text;
$output = $reader->decode($path);
dd($output);
Hopefully, it will be helpful for you.

Snappy / WKHTMLtoPDF - How to change the save folder

I'm using Laravel with the snappy wrapper. It is all working except that it saves the PDF's into the public folder. I want it to go to a different folder. There is nothing obvious on the snappy git site, nor in the config. And the wkhtlptopdf docs are very sparse imho. How do I change the $pdf->save() statement so it goes where I want it to go ?
My PDF is generated by laravel like this:
if( $email == 'email'){
$quotation = $this->quotation->get_PdfQuote($ref);
$pdf = PDF::loadView('quotations/pdf_quotation',compact('quotation') );
$pdf->save($ref.'.pdf'); //THIS SAVES INTO THE PUBLIC FOLDER.
$title = 'Your Quotation';
$firstname = $customer['firstname1'];
$pathtoFile = '/var/www/auburntree/public/'.$ref.'.pdf';
Mail::send('emails.quotation', ['title' => $title, 'firstname'=>$firstname ], function ($m) use($customer,$pathtoFile) {
$m->from('myemail#gmail.com', 'Auburntree');
$m->to($customer['email1'],($customer['firstname1'] . $customer['lastname1']))->subject('Your Quotation');
$m->attach($pathtoFile);
});
Flash::success('The Quote Has Been Saved. An Email has ben sent to the customer ');
return redirect ('quotes');
} else
Ok, I hope this helps someone else.
$quotation = $this->quotation->get_PdfQuote($ref); //pulled in from DB
$pdf = PDF::loadView('quotations/pdf_quotation',compact('quotation') );
$filename = base_path('public/pdf/'.$ref.'.pdf');
$pdf->save($filename);

file name automatically change when i upload the file

I'm new to CodeIgniter and having the following issue. When I upload a file, its successfully uploaded on my local folder and the file name saved to the db. The problem is, file name has been changed after uploading.
eg:
file name "screenshot image 123.png" -> "screenshot_image_123.png"
It just convert the space into underscore;this issue occurred only when the file name having space.Other than this issue all the other files uploading successfully. Given below is my code which I used on my controller page:
public function upload_pic()
{
$image_path = realpath(APPPATH . '../uploads');
$config['upload_path'] = $image_path;
$config['allowed_types'] = "gif|jpg|jpeg|png";
$config['file_name'] = $_FILES['file']['name'];
$config['encrypt_name'] = TRUE;
$config['overwrite'] = TRUE;
$this->load->library('upload',$config);
$this->upload->initialize($config);
if(!$this->upload->do_upload('file'))
{
echo $this->upload->display_errors();
}
else
{
$finfo=$this->upload->data();
$data['uploadInfo'] = $finfo;
}
}
Can anyone help me????
Try before saving file name generate some unique
$filename = $_FILES['file']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$filename = sha1_file($filename). md5(date('Y-m-d H:i:s:u')) . '.'. $ext; //not only this you can generate any format
$config['file_name'] = $filename; //Use this file name is db too

not able to save file in files/myuploads folder in drupal 6

I want to upload a file inside the sites/default/files/myuploads folder. But I am not able to. Actually I am not able to upload the file to any of the folder inside sites/default/files/myuploads.
Here is my code:
$validators = array('file_validate_extensions' => array('se', 'SE'));
$file = file_save_upload('fname',$validators, 'public://myuploads', FILE_EXISTS_REPLACE);
if ($file) {
$fid = $file->fid;
$doc_url = file_create_url($file->uri);
//Set the status of the uploaded file.
$file->status = FILE_STATUS_PERMANENT;
//other code...
}
The upload will work fine if I just give public://. So it will be in the sites/default/files folder. And when I print the $file, in that the ["destination"] => "sites/default/files/./test.se"
How can I do this? Any idea how I can upload into the myuploads folder ?
Verify the write permission for "myuploads" folders.
Change the $validators variable like this:
$validators = array('file_validate_extensions' => array('se SE'));

Setting Sharepoint File Field Attributes

In out SP site, we have a library with files. These are files associated with a user. We now cstomized the user's profiles to accept a list of files. And now, to this list of files in the user's profile, we would like to add a reference to the file so that the user doesn't have to upload again.
Current Library:
/personal/my/User Files/[filename]
So, I was wondering how to do this? The data looks like this in the new User Files field (JSON):
{
[
{
"Id":"1",
"Title":"Test",
"Url":"\/personal\/my\/User+Files\/testfile.doc"
}
]
}
I have a csv file that I iterate over. The csv file contains the user name:filename pairs.
The Id value has to be gotten from the SP instance libarary at that location for that file.
Powershell code:
$upAttribute = "UserFiles"
$profile_info = Import-Csv profiles.csv
foreach ($row in $profile_info) {
$userId = $row.user # User ID
$fullAdAccount = $adAccount += $userId
#Check to see if user profile exists
if ($profileManager.UserExists($fullAdAccount))
{
$up = $profileManager.GetUserProfile($fullAdAccount)
$upAttributeValue += $row.filename # Filename
# CODE ??????
$up.Commit()
}
}
That is the all the data that I have.
Thanks for any and all help.
Eric
You will first need to add the custom property to the User Profile like so:
http://www.paulgrimley.com/2011/02/adding-custom-user-profile-property-to.html
Then this should help you out:
http://get-spscripts.com/2010/07/modify-single-value-user-profile.html
#Get user profile and change the value
$up = $profileManager.GetUserProfile($adAccount)
$up[$upAttribute].Value = $upAttributeValue
$up.Commit()