nuovo/spreadsheet-reader

xlsx not readable in wordpress

Closed this issue · 0 comments

Hi, I'm developing a Wordpress plugin where I need to upload xlsx files, but after i upload the file and I try to open it there's an error,

SpreadsheetReader: File (C:/xampp/htdocs/127.0.0.1/wp-content/uploads/2019/04/KDP.xlsx) not readable

This is what I'm doing:

	        if(isset($_FILES['test_upload_pdf'])){
                $pdf = $_FILES['test_upload_pdf'];
 
                $uploaded=media_handle_upload('test_upload_pdf', 0);

                if(is_wp_error($uploaded)){
                        echo "Error uploading file: " . $uploaded->get_error_message();
                }else{
                	$year = date('Y');
	      			$month = date('m');
	      			$targetPath = get_site_url()."/wp-content/uploads/".$year."/".$month."/".$_FILES['test_upload_pdf']['name'];
	      			$targetPath2 = $_SERVER['DOCUMENT_ROOT']."/".$_SERVER["HTTP_HOST"]."/wp-content/uploads/".$year."/".$month."/".$_FILES['test_upload_pdf']['name'];
					try
					{
		            	$Reader = new SpreadsheetReader($targetPath2);
					}
					catch (Exception $E)
					{
					    echo $E -> getMessage();
					}
				}
			}

I've tried with

get_site_url // using this i get http://127.0.0.1/wordpress/wp-content/uploads/2019/04/example.xlsx

and

$_SERVER['DOCUMENT_ROOT']."/".$_SERVER["HTTP_HOST"] // With this one i get this: C:/xampp/htdocs/127.0.0.1/wp-content/uploads/2019/04/KDP.xlsx

But I always get the error message above mentioned.

What can i do?