Jump to content

Unable to Load Image Data


hobbiton73

Recommended Posts

I wonder whether someone may be able to help me please.

 

I'm trying to put together a PHP within Aurigma Image Uploader which will create an image gallery. To do this I need to extract the image from a folder called 'Thumbnails' and image data from a file called 'files.xml'.

 

The code below is an extract of the default script that performs this functionality and I've tested and it works without any issues.

 

<?php 
   
  //This variable specifies relative path to the folder, where the gallery with uploaded files is located. 
  //Do not forget about the slash in the end of the folder name. 
  $galleryPath = 'UploadedFiles/'; 
    
  $thumbnailsPath = $galleryPath . 'Thumbnails/'; 
    
  $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR; 
    
  $descriptions = new DOMDocument('1.0'); 
  $descriptions->load($absGalleryPath . 'files.xml'); 
?>

 

I have now changed my folder and file structure to the following:

 

UploadedFiles (Folder)

  • username (Subfolder containing the 'location' folder)
  • location (Subfolder containing 'Thumbnails folder and image, and 'files.xml')

Please note that both the 'username' and 'location' folders are dynamically created when the user initially uploads the images.

To try and accomodate the new file structure I changed my code to:

 

<?php 
   
  //This variable specifies relative path to the folder, where the gallery with uploaded files is located. 
  //Do not forget about the slash in the end of the folder name. 
  $galleryPath = 'UploadedFiles/'; 
    
  $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR . $usernamefolder . DIRECTORY_SEPARATOR . $locationfolder . DIRECTORY_SEPARATOR; 
  
  $thumbnailsPath = $galleryPath . 'Thumbnails/'; 
  
  $descriptions = new DOMDocument('1.0'); 
  $descriptions->load($absGalleryPath . 'files.xml'); 
?>

 

But when I run this I receive the following error:

 

d333603417/htdocs/development/UploadedFiles/files.xml" in /homepages/2/d333603417/htdocs/development/gallery.php on line 14

Line 14 is this line:

$descriptions->load($absGalleryPath . 'files.xml'); 

 

I've been working on this for days and I just can't seem to find the answer.

 

I just wondered whether someone could possibly look at this and let me know where I'm going wrong.

 

If it helps, I've added the upload script below.

 

<?php
require_once 'Includes/gallery_helper.php'; 
require_once 'ImageUploaderPHP/UploadHandler.class.php'; 
$galleryPath = 'UploadedFiles/'; 

function onFileUploaded($uploadedFile) { 
  global $galleryPath; 

  $packageFields = $uploadedFile->getPackage()->getPackageFields(); 
  $username=$packageFields["username"]; 
  $locationid=$packageFields["locationid"]; 
  $username = preg_replace('/[^a-z0-9_\-\.()\[\]{}]/i', '_', $_POST['username']); 
  $location = preg_replace('/[^a-z0-9_\-\.()\[\]{}]/i', '_', $_POST['locationid']); 
  $dirName = preg_replace('/[^a-z0-9_\-\.()\[\]{}]/i', '_', $_POST['folder']); 

  $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR . $username . DIRECTORY_SEPARATOR . $location . DIRECTORY_SEPARATOR; 
  $absThumbnailsPath = $absGalleryPath . 'Thumbnails' . DIRECTORY_SEPARATOR; 

  if (!is_dir($absGalleryPath)) mkdir($absGalleryPath, 0777, true); 
  chmod($absGalleryPath, 0777); 
  if (!is_dir($absGalleryPath . $dirName)) mkdir($absGalleryPath . $dirName, 0777, true); 
  chmod($absGalleryPath . $dirName, 0777); 

  if ($uploadedFile->getPackage()->getPackageIndex() == 0 && $uploadedFile->getIndex() == 0) 
    initGallery($absGalleryPath, $absThumbnailsPath, FALSE); 

  $originalFileName = $uploadedFile->getSourceName(); 
  $files = $uploadedFile->getConvertedFiles(); 
  $sourceFileName = getSafeFileName($absGalleryPath, $originalFileName); 
  $sourceFile = $files[0]; 

  if ($sourceFile) $sourceFile->moveTo($absGalleryPath . $sourceFileName); 
  $thumbnailFileName = getSafeFileName($absThumbnailsPath, $originalFileName); 
  $thumbnailFile = $files[1]; 
  if ($thumbnailFile) $thumbnailFile->moveTo($absThumbnailsPath . $thumbnailFileName); 
  
  $descriptions = new DOMDocument('1.0', 'utf-8'); 
  $descriptions->load($absGalleryPath . 'files.xml'); 
  
  $xmlFile = $descriptions->createElement('file'); 
  // <-- please check the following line 
  $xmlFile->setAttribute('name', $_POST['folder'] . '/' . $originalFileName); 
  $xmlFile->setAttribute('source', $sourceFileName); 
  $xmlFile->setAttribute('size', $uploadedFile->getSourceSize()); 
  $xmlFile->setAttribute('originalname', $originalFileName); 
  $xmlFile->setAttribute('thumbnail', $thumbnailFileName); 
  $xmlFile->setAttribute('description', $uploadedFile->getDescription()); 
  $xmlFile->setAttribute('username', $username); 
  $xmlFile->setAttribute('locationid', $locationid); 
  $xmlFile->setAttribute('folder', $dirName); 


  $descriptions->documentElement->appendChild($xmlFile); 
  $descriptions->save($absGalleryPath . 'files.xml'); 
} 

$uh = new UploadHandler(); 
$uh->setFileUploadedCallback('onFileUploaded'); 
$uh->processRequest(); 
?>

 

Many thanks

Link to comment
Share on other sites

I started by trying to understand the error, but it seems you are not giving us the complete error message... Maybe there is some data being written out before it, and because of that it hides along with the HTML? Check the source of the site with the error, to see if you can get the complete error message! :)

Link to comment
Share on other sites

Hi many thanks for replying to my post, and apologies for not providing all you needed.

 

The full error momentarily flashes on the screen but I've managed to capture it here:

 

Warning:DOM Document::load(): I/O warning : failed to load external entity "/homepages/2/d333603417/htdocs/development/UploadedFiles/files.xml" in /homepages/2/d333603417/htdocs/development/gallery.php on line 14
Kind regards

 

Chris

Link to comment
Share on other sites

Hi many thanks for replying to my post, and apologies for not providing all you needed.

 

The full error momentarily flashes on the screen but I've managed to capture it here:

 

domdocument.load]: I/O warning : failed to load external entity "/homepages/2/d333603417/htdocs/development/UploadedFiles/files.xml" in /homepages/2/d333603417/htdocs/development/gallery.php on line 14

 

Kind regards

 

Chris

domdocument seems to fail loading the file. Perhaps it doesn't like the path?

Link to comment
Share on other sites

Hi many thanks for replying to my post, and apologies for not providing all you needed.

 

The full error momentarily flashes on the screen but I've managed to capture it here:

 

Warning:DOM Document::load(): I/O warning : failed to load external entity "/homepages/2/d333603417/htdocs/development/UploadedFiles/files.xml" in /homepages/2/d333603417/htdocs/development/gallery.php on line 14

 

and this is how it's shown when I go into view source:

 

DOMDocument::load() [<a href='domdocument.load'>domdocument.load</a>]: I/O warning : failed to load external entity "/homepages/2/d333603417/htdocs/development/UploadedFiles/files.xml" in <b>/homepages/2/d333603417/htdocs/development/gallery.php</b> on line <b>14</b><br />
Kind regards

 

Chris

Link to comment
Share on other sites

Hi, yes that's what I thought the issue would be, and that's really the problem I have, now my file and folder structure have changed I'm not sure how to send it to the correct filepath.

 

Regards

Give it the real local path. If it's in the same folder as the script, you can use realpath.

If the file is in the same folder, give realpath the name of the file, if not you can also aim at it by browsing around by writing . (dot) for the same folder as you are currently in, and to go one folder up .. (doubledot).

Link to comment
Share on other sites

Hi, many thanks for this.

 

Using the link that you provided I've read through this read additional material on 'realpath' but I must ahve misunderstood something along the way. I''ve put together the followimg:

 

<?php
chdir('/var/www/');
echo realpath('./././files.xml);
?>

and called it 'real.php', but when I run this, I don't receive the file path, nor any any error. The screen is just blank.

 

My file structure is

 

UploadedFiles Folder containing 'real.php' file and 'username' folder

  • 'username' folder (Subfolder containing 'location' folder)
  • 'location' folder (Subfolder containing 'files.xml')

 

I'm sure I'm just making a beginners mistake here, but I just wondered if you could perhaps look at this please and let me know where I'm going wring?

 

Many thanks and kind regards

Link to comment
Share on other sites

Hi, many thanks for this.

 

Using the link that you provided I've read through this read additional material on 'realpath' but I must ahve misunderstood something along the way. I''ve put together the followimg:

 

<?php
chdir('/var/www/');
echo realpath('./././files.xml);
?>

and called it 'real.php', but when I run this, I don't receive the file path, nor any any error. The screen is just blank.

 

My file structure is

 

UploadedFiles Folder containing 'real.php' file and 'username' folder

  • 'username' folder (Subfolder containing 'location' folder)
  • 'location' folder (Subfolder containing 'files.xml')

 

I'm sure I'm just making a beginners mistake here, but I just wondered if you could perhaps look at this please and let me know where I'm going wring?

 

Many thanks and kind regards

The dot is only useful to get the current folders path.

 

Let me show you...

If for example I print this:

realpath('.');

it would for example say this:

C:\web\Apache2\htdocs\somefolder\somefolder2

This would be the folder where your script runs, it's a good way to create a path to save something in the same folder that doesn't already exist.

 

Let us pretend there was some file in the same folder called test.php

realpath('test.php');

would return

C:\web\Apache2\htdocs\somefolder\somefolder2\test.php

 

Now if the file was stored in a folder with this path:

C:\web\Apache2\htdocs\someotherfolder

You could write this to return the real path of the file:

realpath('..\..\someotherfolder\test.php');

It would return:

C:\web\Apache2\htdocs\someotherfolder\test.php

Of course only if the files and folders exists. :)

Link to comment
Share on other sites

Hi, many thanks for your continued help with this.

 

I'm starting to work through the examples you kindly provided, and after some head scratching I've started to get the desired results.

 

Many thanks for all your time and trouble.

 

Kind regards

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.