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
Related
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/';
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
I want to only upload images, the docs says use finfo_open.
http://www.php.net/manual/en/function.finfo-file.php
I do this but I get this error:
Fatal error: Call to undefined function finfo_open() in
C:\xampp\htdocs\ticket\index.php on line 83 Call Stack
Time Memory Function Location 1 2.2551 158752 {main}( ) ..\index.php:0
PHP:
if(isset($_FILES['file'])) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$ext = finfo_file($finfo, $_FILES['file']['name']); << LINE 84
if(substr($ext, 0, 5) != 'image') {
$errors[] = 'Kon dit bestand type niet uploaden.';
}
}
Why does this not work?
UPDATE:
By settings extension=php_fileinfo.dll active I get this now:
Warning: finfo_file(download.jpg): failed to open stream: No such file
or directory in C:\xampp\htdocs\ticket\index.php on line 84 Call Stack
Time Memory Function Location 1 2.2531 158448 {main}( ) ..\index.php:0 2 3.2572 180560 finfo_file ( ) ..\index.php:84
PHP 5.3.0 and later have Fileinfo built in, but on Windows you must enable it manually in your php.ini
Have a look at your php.ini file and check that the fileinfo.so or php_fileinfo.dll is activated (depending on your platform and version).
There should be a line similar to
extension = fileinfo.so
on windows
extension = fileinfo.dll
in your php.ini file
AFTER UPDATE
use $_FILES['file']['tmp_name'] for path (finfo_file() need path!)
if(isset($_FILES['file'])) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$ext = finfo_file($finfo, $_FILES['file']['tmp_name']);
if(substr($ext, 0, 5) != 'image') {
$errors[] = 'Kon dit bestand type niet uploaden.';
}
}
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.
I am having trouble reading a file with PHPExcel. Here is the error I'm getting:
( ! ) Fatal error: Class 'PHPExcel_Cell' not found in /Applications/MAMP/htdocs/TestRailIntegration/Classes/PHPExcel/Reader/Excel2007.php on line 739
Call Stack
# Time Memory Function Location
1 0.0023 649920 {main}( ) ../testRailScripting.php:0
2 0.0030 755712 PHPExcel_IOFactory::load( ) ../testRailScripting.php:23
3 0.0038 797288 PHPExcel_Reader_Excel2007->load( ) ../IOFactory.php:193
And here is my code:
<?php
include './Classes/PHPExcel.php';
echo 'Hello world' . "\n";
$FileName = $_FILES["fileName"]["name"];
$inputFileName=$_FILES["fileName"]["tmp_name"];
echo $inputFileName;
if(file_exists("uploadedFiles/".$_FILES["fileName"]["name"])){
echo $_FILES["fileName"]["name"]." already exists";
}
else{
move_uploaded_file($_FILES["fileName"]["tmp_name"],"uploadedFiles/".$_FILES["fileName"]["name"]);
echo $_FILES["fileName"]["name"]." has been moved";
}
$PHPExcelObj = PHPExcel_IOFactory::load($inputFileName);
?>
I see you moved the file to "uploadedFiles" folder so:
$PHPExcelObj = PHPExcel_IOFactory::load("uploadedFiles/".$inputFileName);