Jump to content

noob help please - include core php here?


ZandarGlass
Go to solution Solved by Ch0cu3r,

Recommended Posts

Hi all. I'm teaching myself PHP and of course I have a stumbling block. I wrote a simple upload file, and it worked fine (so permissions don't seem to be my issue), then I added some other code to it to create a PHP class (using PHP SOLUTIONS by DAVID POWERS). But the code fails now. I'm pretty sure it can't find a path to necessary php core functions. The error message I get is:

 

 

Fatal error: require_once() [function.require]: Failed opening required '../classes/Ps2/Upload.php' (include_path='.;C:\php5\pear') in D:\Hosting\myaccount\html\mydirectory\Upload_file.php on line 7

 

And indeed, when I use a phpinfo code to glean information, it tells me the include path I must is:

 

.;C:\php5\pear

 

 

It all makes perfect sense. However, I can't seem to write an include statement that addresses the issue. I want to put it in the same document (my upload_file.php), but if that isn't necessary I want to put it anywhere else that would work.

 

Any help? Either this is very simple or I have an issue of some kind at the server?

 

I can post the entire code if you like. Whatever helps.

Link to comment
Share on other sites

After some thought I figured I'd answer the inevitable question, heres the code behind the file I'm using. I can include the file in the Ps2 directory (Upload.php) if this also helps. I changed some details in the path so my account and the folder aren't appearing.

 

 

<?php
// set the maximum upload size in bytes
$max = 51200;
if (isset($_POST['upload'])) {
  // define the path to the upload folder
  $destination = '/Hosting/myacount/html/mydir/tst/';
  require_once('../classes/Ps2/Upload.php');
  try {
    $upload = new Ps2_Upload($destination);
    $upload->move();
    $result = $upload->getMessages();
  } catch (Exception $e) {
    echo $e->getMessage();
  }
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset=utf-8">
<title>Upload File</title>
</head>

<body>
<?php
if (isset($result)) {
  echo '<ul>';
  foreach ($result as $message) {
    echo "<li>$message</li>";
  }
  echo '</ul>';
}
?>
<form action="" method="post" enctype="multipart/form-data" id="uploadImage">
  <p>
    <label for="image">Upload image:</label>
    <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max; ?>">
    <input type="file" name="image" id="image">
  </p>
  <p>
    <input type="submit" name="upload" id="upload" value="Upload">
  </p>
</form>
</body>
</html>

Link to comment
Share on other sites

Thanks for the response. So if I understand correctly, I have to have upload.php in the same folder as the file that is calling it (which is called upload_file.php)? Isn't there a way to right some kind of include path statement in upload_file.php that tells it that upload.php is in one folder, and the "core php" file is in C:/php5/pear? Or do you mean those all have to be in the same folder? I'm not sure if I have access to place both upload_file.php and upload.php in the c:/php5/pear folder (or any of my files). 

 

Sorry to sound dense.

Link to comment
Share on other sites

If I'm understanding correctly, then something like this:

 

 

 

<?php
// set the maximum upload size in bytes
$max = 51200;
if (isset($_POST['upload'])) {
  // define the path to the upload folder
  $destination = '/Hosting/myacount/html/mydir/tst/';
  require_once('../classes/Ps2/Upload.php');

 

 

  require_once('.;C:\php5\pear');

 

  try {
    $upload = new Ps2_Upload($destination);
    $upload->move();
    $result = $upload->getMessages();
  } catch (Exception $e) {
    echo $e->getMessage();
  }
}
?>

 

I'm not sure  I understand the syntax. Sorry for the difficulty, I really do appreciate the help!

 

I've also been reading about include_path, and wonder if this is what you are referring to, as in this example I found at php.net

 

<?php
$path 
'/usr/lib/pear';
set_include_path(get_include_path() . PATH_SEPARATOR $path);
?>

 

where '/usr/lib/pear' would be changed to the location of the folder on my server. In that case, maybe something like:

 

<?php

 

$path '/php5/pear'';
set_include_path(get_include_path() . PATH_SEPARATOR $path);
 

// set the maximum upload size in bytes
$max = 51200;
if (isset($_POST['upload'])) {
  // define the path to the upload folder
  $destination = '/Hosting/myacount/html/mydir/tst/';
  require_once('../classes/Ps2/Upload.php');
  try {
    $upload = new Ps2_Upload($destination);
    $upload->move();
    $result = $upload->getMessages();
  } catch (Exception $e) {
    echo $e->getMessage();
  }
}
?>

 

 

I'm not sure if I have access to php.ini on my host server (windows host).

 

Thanks again for any help you can provide.

Link to comment
Share on other sites

  • Solution

Is the code from the book you're reading? 

https://github.com/lisawilliams/phpsols

 

If it is then ignore the include_path setting. You do not need to be modifying it. The problem is a file path issue.

 

Is the classes/Ps2/ folder in the D:\Hosting\myaccount\html\mydirectoryIf it is then you need to require the Upload.php class using this (remove the ../ from the file path)

require_once('classes/Ps2/Upload.php');

The ../ in file path means go up one directory,  If you're requiring the Upload.php file using ../classes/Ps2/Upload.php as the file path then PHP will try to find Upload.php from D:\Hosting\myaccount\html\classes\Ps2 folder. I am guessing that classes/Ps2 is actually in the D:\Hosting\myaccount\html\mydirectory folder?

Link to comment
Share on other sites

If you have set of include files all in one folder then it is easier to add that folder to the included_files path, so it would become

.;C:\php5\pear;D:\Hosting\myaccount\html\classes\Ps2

if that is where the files are.

 

Then you only need

include('filename');

without worrying about the path

Link to comment
Share on other sites

Ch0cu3r DUDE you nailed it. I kept wondering why other code was working and this one failed - all I could think of was some core function was missing. I kept looking at it and didn't notice the ".." until you called it out!!! Thanks a ton. (yes that is the book)


BARAN Thanks to you too! Every time I look for answers for one question I learn more - so none of that went to waste! It all sent me looking and learning other methods.

 

I really appreciate getting such expert advice from both of you guys!

 

I'm sure I'll be back asking more questions as the examples get more complex - but you dam sure bet I'll be looking for an errant path a little closer. So far I've been able to troubleshoot my own errors but THIS one - I just could NOT get over the hump.

 

Thanks again guys!!!! You have been so much help!
 

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.