Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I try to copy some files from one directory on server to another, but it does not work.
Here is my code:
system('cp /var/www/site1/images/' . $row['imageUrl']. ' /var/www/site2/content/upload/content/item/mid/' . $row['imageUrl']);
$file = '/var/www/site1/images/'.$row['imageUpl'];
$newfile = '/var/www/site2/content/upload/content/item/mid/'.$row['imageUpl'];
if (copy($file, $newfile)) {
echo "success";
}
else
{
echo "failed";
}
Look at the copy() function here: http://php.net/manual/ru/function.copy.php
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am new to PHP, FTP connection.
I have to check a folder on a remote location ( ftp location ) that whether this folder exist or not.
I have tried through curl but it is not showing correct result.
maybe it would be easier to use an FTP PHP library , try this one php-ftp-library
try to use this code:
<?php
$path = 'your file name';
if (!is_dir($path)) {
//do something
} else {
//do something else
}
?>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
hy developers, i want to download multiple files as a zip, but i keep getting errors
below is the code i have tried
public function multiple($id){
$files = documents::where('claim_id', $id)->get();
if ($files != '') {
$filepath = storage_path('app/Documents/');
foreach($files as $file) {
$zipper = new \Chumper\Zipper\Zipper;
$fi = storage_path('app/Documents/'.$file->file_name);
$zipper->make($filepath.'doc.zip');
}
return response()->download($filepath.'doc.zip');
}
else{
Alert::info('Info', 'No Documents Available');
return redirect()->back();
}
}
attached is the error i get
Looks like you didn't add any files to your Zip.
I think:
$zipper->make($filepath.'doc.zip');
Should be:
$zipper->make($filepath.'doc.zip')->add($fi)->close();
Make sure the files and zip are in the storage folder.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
Here is my email send php file , email sent but attachment is not working. File is there on that path . Issue is I need to get file name from a linux command and store in a variable . When I called that variable attachment is not working.
<?php
require_once('phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$file_name1 = shell_exec('sed "1q;d" /tmp/file.txt');
$file = "/home/user/.$file_name1";
echo $file;
//set Address data
$mail->Subject = "Acknowledgement Files ".date("m-d-Y:h:i:s")." ";
$mail->MsgHTML(" Acknowledgement Files are here attached");
$mail->AddAttachment($file)
if($mail->Send()) {
echo "Message sent!";
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
?>
If I am going to use full path like
$file = "/home/user/filetxt"
this works but I want to call variable and echo is display correct name.
any thoughts?
Put your variable outside the quotation, like this:
$file = "/home/user/".$file_name1;
So I found issue and solution as well. So when we run any command on linux likels /path/ output is result\n. It adds new line charactor as well. So I changed this line
$file_name1 = shell_exec('sed "1q;d" /tmp/file.txt');
to
$file_name1 = trim(shell_exec('sed "1q;d" /tmp/file.txt'));
to remove new line . AND now it works
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am using a cross domain request.A request has been made to php file in a server via ajax from another server.From php side Here, I need to create a file and write some contents in that file.My request is reaching perfectly.But I am not able to create a file.Please help
NOTE : ITS A CROSS DOMAIN REQUEST
<?php
$filename = "lin.txt";
$data2 = "lin IS HERE";
$newFile= fopen($filename, 'w');
chmod($newFile, 777);
fwrite($newFile, $data2);
fclose($newFile);
?>
Thanks in advance
In am not sure what are you going to do, because you haven't told us your code. I think this will help you:
<?php
$file = 'demo.txt';
$content = "Example\n";
file_put_contents($file, $content);
?>
The file is demo.txt (it is at the same location with the PHP document.
$content is the text which will be put on your txt file.
Hope it helps!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
You are right some people are really blind and dumb.
I think that your problem is the file permission.
You must change the file permissions of your images (0644 or 0777 in your chase).
Please read this: http://php.net/manual/en/function.chmod.php.
You can delete images in PHP using the unlink() function.
unlink('path/to/file.jpg');
See http://php.net/manual/en/function.unlink.php .
EDIT:
ALSO you can try this:
if(is_writable($filename))
{
unlink($filename)
} else {
echo 'At this moment this file can't be deleted';
chmod(" YOUR PATH OF $filename", 0777);
unlink($filename);
}
AND
if (file_exists('YOUR PATH OF $filename')) {
echo 'File exist... Sorrrrrrrrrry!!!!!!!!!!!!';
}