PHP Function rename fails “No such file or directory"… - php

Rename Functions fails. i already tried a lot of different solutions of this forum but nothing helps.
This is my Code:
$dirname='rechnungen/';
$handleu=opendir($dirname);
while ( $ufile = readdir ( $handleu ) ) {
$ufile = substr($ufile,11);
foreach ($mydata as $nr => $uinhalt)
{
$ufilename = $uinhalt['File'].'.pdf';
if($ufilename == $ufile) {
rename($dirname.$ufile, $dirname.'ER'.$uinhalt['Zahl'].'_'.$ufile );
}
}
}
closedir( $handleu );
I get this warnings:
Warning: rename(rechnungen/REGW-2020-143.pdf,rechnungen/ER013_REGW-2020-143.pdf): No such file or directory in /volume1/web/sevdesk/rechnungen.php on line 162
Warning: rename(rechnungen/REGW-2021-011.pdf,rechnungen/ER011_REGW-2021-011.pdf): No such file or directory in /volume1/web/sevdesk/rechnungen.php on line 162
Warning: rename(rechnungen/REGW-2021-014.pdf,rechnungen/ER015_REGW-2021-014.pdf): No such file or directory in /volume1/web/sevdesk/rechnungen.php on line 162
Warning: rename(rechnungen/REGW-2021-009.pdf,rechnungen/ER012_REGW-2021-009.pdf): No such file or directory in /volume1/web/sevdesk/rechnungen.php on line 162
Warning: rename(rechnungen/REGW-2021-007.pdf,rechnungen/ER014_REGW-2021-007.pdf): No such file or directory in /volume1/web/sevdesk/rechnungen.php on line 162
Can you help me with that?

try to change the paths in ../rechnungen/file.pdf,
may you have to use the full path and you have to give the files and directories full permissions.
$path = "/volume1/web/sevdesk/";
$dirname= $path.'rechnungen/';

Related

PHP Warning: include_once()

I need help with these few errors here
`[06-May-2018 20:08:16 America/New_York] PHP Warning: include_once(unifont/ttfonts.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/squid/lib/tfpdf.php on line 507
[06-May-2018 20:08:16 America/New_York] PHP Warning: include_once(): Failed opening 'unifont/ttfonts.php' for inclusion (include_path='.:/Applications/MAMP/bin/php/php5.4.45/lib/php') in /Applications/MAMP/htdocs/squid/lib/tfpdf.php on line 507
[06-May-2018 20:08:16 America/New_York] PHP Fatal error: Class 'TTFontFile' not found in /Applications/MAMP/htdocs/squid/lib/tfpdf.php on line 508`
This is the line 507:
if (!isset($type) || $type != "TrueTypesubset") {
include_once($this->_getfontpath().'unifont/ttfonts.php');
line 507>>> $ttf = new TTFontFile();
And this is line 508
$ttf = new TTFontFile();
I updated the paths to this :
if ($uni) {
if (defined("_SYSTEM_TTFONTS") && file_exists(_SYSTEM_TTFONTS.$file )) { $ttfilename = _SYSTEM_TTFONTS.$file ; }
else { $ttfilename = $this->_getfontpath().'/Applications/MAMP/htdocs/squid/lib/font/unifont/'.$file ; }
$filename = $file;
$filename =str_replace(' ','',$filename );
$filename =str_replace('-','',$filename );
$unifilename = $this->_getfontpath().'unifont/'.strtolower(substr($filename ,0,(strpos($filename ,'.'))));
$diff = '';
$enc = '';
if (file_exists($unifilename.'.mtx.php')) {
include($unifilename.'.mtx.php');
}
if (!isset($type) || $type != "TrueTypesubset") {
include_once($this->_getfontpath().'/Applications/MAMP/htdocs/squid/lib/font/');
$ttf = new TTFontFile();
This is the font folder:
squid\lib\tfpdf\font
full path: /Applications/MAMP/htdocs/squid/lib/font/
This is the unifont folder
squid\lib\tfpdf\font\unifont
Full path: /Applications/MAMP/htdocs/squid/lib/font/unifont
When i change the paths i get this error:
[08-May-2018 14:38:02 America/New_York] PHP Warning: include_once(/Applications/MAMP/htdocs/squid/lib/font/): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/squid/lib/tfpdf.php on line 507
[08-May-2018 14:38:02 America/New_York] PHP Warning: include_once(): Failed opening '/Applications/MAMP/htdocs/squid/lib/font/' for inclusion (include_path='.:/Applications/MAMP/bin/php/php5.4.45/lib/php') in /Applications/MAMP/htdocs/squid/lib/tfpdf.php on line 507
[08-May-2018 14:38:02 America/New_York] PHP Fatal error: Class 'TTFontFile' not found in /Applications/MAMP/htdocs/squid/lib/tfpdf.php on line 508
include_once($this->_getfontpath().'/Applications/MAMP/htdocs/squid/lib/font/');
This gives an error because you're trying to include an entire folder, you need to specify a filename
$ttf = new TTFontFile();
This gives an error because the class TTFontFile is not defined, maybe its in another file that you didn't include.
Seems like the path returned by
$this->_getfontpath()
is incorrect, or the file you are looking to include is not installed at that path.
You should figure out what $this->_getfontpath() returns, where it is defined. Then see if that path exists and what files are there. Also reading the docs for the library you are installing should help you troubleshooting.
Try changing
/Applications/MAMP/htdocs/squid/lib/font/
to
/squid/lib/font/
does that help?

Error when running my php script

I have these errors when running my script.
failed to open dir: No such file or directory in /Applications/MAMP/htdocs/sites-store/word/word2.php on line 6
Warning: scandir(): (errno 2): No such file or directory in /Applications/MAMP/htdocs/sites-store/word/word2.php on line 6
Warning: array_diff(): Argument #1 is not an array in /Applications/MAMP/htdocs/sites-store/word/word2.php on line 6
Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/sites-store/word/word2.php on line 7
Well this is my code below, I don't understand why it failed to open my dir when it's being declared below? Can someone help me with this.
Code of my word2.php
<?php
$numargs = count($argv);
if ($numargs > 1) {
$folder = $argv[1];
echo "Folder is: " . $folder . "\n";
$files = array_diff(scandir($folder), array('.', '..')); //line 6
foreach ($files as $file) { //line 7
$filename = str_replace("í»", "", $filename);
}
} else {
echo "You need to pass the folder absolute path";
exit();
}
Code for running my script using this command ./run.bat this is the filename with a code below.
php word2.php "/Applications/MAMP/htdocs/sites-store/word/images"
PAUSE
Try changing your .bat file to
php word2.php -- "/Applications/MAMP/htdocs/sites-store/word/images"
PAUSE
and you should also do var_dump($argv), to see how your script gets its parameter.
failed to open dir: No such file or directory in
/Applications/MAMP/htdocs/sites-store/word/word2.php on line 6
Make sure that your file in that directory.
Check the filename again means is there any spelling mistakes or duplicated.
Make sure if it's read that directory or not

move_uploaded_file / No such file or directory in PHP

i have a problem with the move_uploaded_file function this is the problem:
Warning: move_uploaded_file(/imagenes/Icon.png) [function.move-uploaded-file]: failed to >open stream: No such file or directory in /home/decc98/public_html/php/insert.php on line 6
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpIBBh5U' >to '/imagenes/Icon.png' in /home/decc98/public_html/php/insert.php on line 6
Insercion exitosa
Other stuff, i speak spanish so part of my code is in spanish... Anyways, my code is:
<?php
include "conexion.php";
$ruta = "/imagenes";
$archivo = $_FILES['imagen']['tmp_name'];
$nombreArchivo = $_FILES['imagen']['name'];
move_uploaded_file($archivo,$ruta."/".$nombreArchivo);
$ruta=$ruta."/".$nombreArchivo;
$texto = $_POST['descripcion'];
$id = rand(1,200);
$insertar = mysql_query("INSERT INTO tablaUno VALUES('".$id."','".$ruta."','".$texto."')");
if ($insertar) {
echo "Inserción exitosa";
}else{
echo "Fallo en la inserción";
}
?>
Please if anyone can help me I would appreciate it!
You need to use a relative path instead of an absolute path.
For example:
$ruta = "imagenes";
leaving out the / at the beginning of your folder name, if you're using your script from the root.
Or, something like:
$ruta = "../imagenes";
depending on the script execution's location.
Note: Using / is mostly used for an (server) absolute path, something to the affect of:
/var/user/user123/public_html/imagenes

PHP on WAMP: problems uploading / creating a file

I get this error and I am not sure how to clear it. Not sure if its on my WAMP and if so I have two ini file, development and production, where should I look?
( ! ) Warning: move_uploaded_file(uploadedFiles/gal2.jpg): failed to open stream: No such file or directory in C:\wamp\www\fileupload.php on line 20
Call Stack
# Time Memory Function Location
1 0.0007 257960 {main}( ) ..\fileupload.php:0
2 0.0015 303448 move_uploaded_file ( ) ..\fileupload.php:20
( ! ) Warning: move_uploaded_file(): Unable to move 'C:\wamp\tmp\php71A.tmp' to 'uploadedFiles/gal2.jpg' in C:\wamp\www\fileupload.php on line 20
Call Stack
# Time Memory Function Location
1 0.0007 257960 {main}( ) ..\fileupload.php:0
2 0.0015 303448 move_uploaded_file ( ) ..\fileupload.php:20
The code is below:
$desiredPath = 'uploadedFiles/';
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
print "Picture Info"."<br>";
print_r($_FILES['picture']);
if (move_uploaded_file($_FILES['picture']['tmp_name'], $desiredPath.$_FILES['picture']['name']))
{
print 'File Upload Successful';
print '<div>';
print '<img width="300px" src="'.$desiredPath.$_FILES['picture']['name'].'">';
print '</div>';
}
else
{
print 'File Upload Failed with error code: '.$_FILES['picture']['error'];
}
}
Your code:
$desiredPath = 'uploadedFiles/';
Have you tested that the directory exists, before moving the file to it?
Code below:
if(!file_exists($desiredPath)) {
mkdir($desiredPath, 0755, true);
}
It's just a suggestion. I was trying to create an upload script myself and that little block of code solved all my problems

move_uploaded_file() fails to open stream due to invalid argument - PHP

I have this code to move my uploaded file to a specific directory:
if (isset($_FILES["image"]["name"])){
if (!is_dir('pf/' . $uid)) {
mkdir('pf/' . $uid);
$large_image_location = "pf/" . $uid;
}else {
$large_image_location = "pf/" . $uid;
}
chmod ($large_image_location, 0777);
move_uploaded_file("$userfile_tmp", "$large_image_location/$userfile_tmp");
}
However that gives the following error:
( ! ) Warning: move_uploaded_file(pf/BfyhieniKJGGqTNm/C:\wamp\tmp\phpF08A.tmp) [function.move-uploaded-file]: failed to open stream: Invalid argument in C:\wamp\www\mingle\upload_dp.php on line 26
Any help on how to sort this out would be greatly appreciated!
This is 90% of your woes:
move_uploaded_file("$userfile_tmp", "$large_image_location/$userfile_tmp");
You using the moved to path at the beginning of the upload path. Try:
move_uploaded_file("$userfile_tmp", "$large_image_location/".$_FILES['image']['name']);
That should work better.
The error itself is pretty clear, pf/BfyhieniKJGGqTNm/C:\wamp\tmp\phpF08A.tmp is not a valid filename.
Don't change the contents of $_FILES[n]['tmp_name'] (or $userfile_tmp for that matter), since it will always contain the full path to the uploaded file.

Categories