Jump to content
Larry Ullman's Book Forums

Chapter 5: Add_Pdf. Problem Locating Pdfs File In 'Config' File


Recommended Posts

Hail All

 

I have a problem with naming the location of the pdfs file in the config.inc.php file, which is preventing me from uploading pdfs:

 

config.inc.php

define ('BASE_URI', '/path/to/dir/');

define ('BASE_URL', 'www.wolfcut.co.uk/');

define ('PDFS_DIR', '/wolfcut/pdfs/');

define ('MYSQL', BASE_URI . 'mysql.inc.php');

 

root directory files on my web hosting server (fatcow)

/wolfcut/pdfs/

 

and

 

/wolfcut/includes/config.inc.php

 

error message

move_uploaded_file (/home/users/web/b1384/moo.laissezfairelondonco/wolfcut/wolfcut/pdfs/2

05c5187b34579c5cffbadd181853f3eea53d443_tmp) [function.move-uploaded-file]: failed to open stream: No such file or directory

 

==============

Please help. I've almost finished the first project in Larry's book :)

Many thanks

Link to comment
Share on other sites

Hail Larry - 'The Jedi Master of php'

 

I'm at a loss: I contacted the hosting server and been trying all manor of pathways to the the 'pdfs' folder situated on the server. Here's what I've tried, but still the same type of "...failed to open stream: No such file or directory

..." error message. (Interesting research about server directories in the meantime)

 

 

Already tried, but did not work:

 

define ('PDFS_DIR', BASE_URI . '/ftp.fatcow.com/21/wolfcut/pdfs/');

define ('PDFS_DIR', BASE_URI . '/ftp.fatcow.com/wolfcut/pdfs/');

define ('PDFS_DIR', '/ftp.fatcow.com/21/wolfcut/pdfs/');

define ('PDFS_DIR', '/ftp.fatcow.com/wolfcut/pdfs/');

define ('PDFS_DIR', BASE_URI . '/ftp.fatcow.com/laissezfairelondonco/PASSWORD/21/wolfcut/pdfs/');

define ('PDFS_DIR', BASE_URI . '/ftp.fatcow.com/laissezfairelondoncoPASSWORD/wolfcut/pdfs/');

define ('PDFS_DIR', '/ftp.fatcow.com/laissezfairelondonco/PASSWORD/21/wolfcut/pdfs/');

define ('PDFS_DIR', '/ftp.fatcow.com/laissezfairelondonco/PASSWORD/wolfcut/pdfs/');

define ('PDFS_DIR', $_SERVER['DOCUMENT_ROOT'] . '/wolfcut/pdfs/');

define ('PDFS_DIR', $_SERVER['DOCUMENT_ROOT'] '/ftp.fatcow.com/wolfcut/pdfs/');

define ('PDFS_DIR', '/home/users/web/b1384/moo.laissezfairelondonco/wolfcut/pdfs/');

 

 

Error message in add_pdf.php

 

 

An error occurred in script '/hermes/waloraweb004/b1384/moo.laissezfairelondonco/wolfcut/add_pdf.php' on line 65:

move_uploaded_file(pdfsa59c5ec29a76683da43ef9672987b848c5b6efd0wolfcut/pdfs_tmp) [function.move-uploaded-file]: failed to open stream: No such file or directory

 

 

Line 65 of add_pdf.php

if (move_uploaded_file($file['tmp_name'], $dest)) {

Link to comment
Share on other sites

.... the 'pdfs' directory is in the web root directory .... and

.... is in the same folder as 'add_pdf.php script' .... and

.... I'm using a web hosting server .....

 

hope that helps

(The server organisation is the same as Figure 3.3 on page 54)

Link to comment
Share on other sites

I'm a bit confused, because your two error messages have different paths. To simplify things, since the "pdfs" directory is in the same directory as "add_pdf.php", then you can just use "./pdfs" as the constant value for that directory. That's relative, not absolute, but should be accurate.

Link to comment
Share on other sites

.... I have tried that constant: define ('PDFS_DIR', BASE_URI . './pdfs/');

but still getting this error message:

 

An error occurred in script '/hermes/waloraweb004/b1384/moo.laissezfairelondonco/wolfcut/add_pdf.php' on line 65:

move_uploaded_file(/path/to/dir/./pdfs/df1bd4fbb72e4547143f5b1d4105ad4a83aec2e0_tmp) [function.move-uploaded-file]: failed to open stream: No such file or directory

 

The line 65 oin add_pdf.php is referring to the config.inc.php constant shown above. But here is line 65 from add_pdf.php:

 

 

62 // Move the file to its proper folder but add _tmp, just in case:

63 $dest = PDFS_DIR . $tmp_name . '_tmp';

64

65 if (move_uploaded_file($file['tmp_name'], $dest)) {

 

67 // Store the data in the session for later use:

68 $_SESSION['pdf']['tmp_name'] = $tmp_name;

69 $_SESSION['pdf']['size'] = $size;

70 $_SESSION['pdf']['file_name'] = $file['name'];

 

===============================================================

(I have also made sure the directory permissions have been set to all changes in my web hosting server.)

Link to comment
Share on other sites

I did indeed, just like this:

 

define ('PDFS_DIR', './pdfs');

 

Error still occurs:

 

An error occurred in script '/hermes/waloraweb004/b1384/moo.laissezfairelondonco/wolfcut/add_pdf.php' on line 132:

The PDF could not be added due to a system error. We apologize for any inconvenience.

 

The corresponding error on line 132 in add_pdf.php is this:

 

128 // Clear $file and $_SESSION['pdf']:

129 unset($file, $_SESSION['pdf']);

130

131 } else { // If it did not run OK.

132 trigger_error('The PDF could not be added due to a system error. We apologize for any inconvenience.');

133 unlink ($dest);

134 }

135

136 } // End of $errors IF.

Link to comment
Share on other sites

yep slowly but surely.... I didn't know I had to give these guys values:

 

  $tmp_name = sha1($file['name'] . uniqid('',true));

  // Move the file to its proper folder but add _tmp, just in case:
  $dest =  PDFS_DIR . $tmp_name . '_tmp';
  if (move_uploaded_file($file['tmp_name'], $dest)) {

   // Store the data in the session for later use:
   $_SESSION['pdf']['tmp_name'] = $tmp_name;
   $_SESSION['pdf']['size'] = $size;
   $_SESSION['pdf']['file_name'] = $file['name'];

 

===================

 

On a brighter note, I've complete everything else on knowledge is power, including the paypal side. If you have time, check it out at www.wolfcut.co.uk I'd really like to say thank you again for all your help..... onto Coffee Shop next :)

Link to comment
Share on other sites

I've amended the config fig to take care of that missing '/'.

 

values now read like this:

 

  [HTTP_POST_FILES] => Array
							 (
								 [pdf] => Array
									 (
										 [name] => transformers 2 poster.PDF.pdf
										 [type] => application/pdf
										 [tmp_name] => /tmp/phpumhDHE
										 [error] => 0
										 [size] => 971389
									 )

						    )

					    [_REQUEST] => Array
							 (
								 [MAX_FILE_SIZE] => 1048576
								 [title] => tra
								 [description] => sdfasdf
								 [submit_button] => Add This PDF
								 [phpSESSID] => 08877f9689982589d29fefa1f4ac1137
							 )

					    [live] => 1
						 [contact_email] => jizzwit@gmail.com
						 [HTTP_SESSION_VARS] => Array
							 (
								 [reg_user_id] => 5
								 [user_admin] => 1
								 [user_id] => 5
								 [username] => Armlocker0358
								 [pdf] => Array
									 (
										 [tmp_name] => 81a11224ad91f1fecb9d5c01ac664dce51a4cd7d
										 [size] => 949
										 [file_name] => transformers 2 poster.PDF.pdf
									 )

						    )

					    [_SESSION] => Array
							 (
								 [reg_user_id] => 5
								 [user_admin] => 1
								 [user_id] => 5
								 [username] => Armlocker0358
								 [pdf] => Array
									 (
										 [tmp_name] => 81a11224ad91f1fecb9d5c01ac664dce51a4cd7d
										 [size] => 949
										 [file_name] => transformers 2 poster.PDF.pdf
									 )

						    )

					    [reg_user_id] => 5
						 [user_admin] => 1
						 [user_id] => 5
						 [username] => Armlocker0358
						 [dbc] => mysqli Object
							 (
							 )

					    [page_title] => Add a PDF
						 [pages] => Array
							 (
								 [Home] => index.php
								 [About] => #
								 [Contact] => #
								 [Register] => register.php
							 )

					    [this_page] => add_pdf.php
						 [v] => register.php
						 [k] => Register
						 [add_pdf_errors] => Array
							 (
							 )

					    [t] => tra
						 [d] => sdfasdf
						 [file] => Array
							 (
								 [name] => transformers 2 poster.PDF.pdf
								 [type] => application/pdf
								 [tmp_name] => /tmp/phpumhDHE
								 [error] => 0
								 [size] => 971389
							 )

					    [size] => 949
						 [tmp_name] => 81a11224ad91f1fecb9d5c01ac664dce51a4cd7d
						 [dest] => ./pdfs81a11224ad91f1fecb9d5c01ac664dce51a4cd7d_tmp
						 [fn] => transformers 2 poster.PDF.pdf
						 [q] => INSERT INTO pdfs (tmp_name, title, description, file_name, size) VALUES ('81a11224ad91f1fecb9d5c01ac664dce51a4cd7d', 'tra', 'sdfasdf', 'transformers 2 poster.PDF.pdf', 949)
						 [r] =>
					 )

		    )

    )

   [1] => Array
	 (
		 [file] => /hermes/waloraweb004/b1384/moo.laissezfairelondonco/wolfcut/add_pdf.php
		 [line] => 134
		 [function] => trigger_error
		 [args] => Array
			 (
				 [0] => The PDF could not be added due to a system error. We apologize for any inconvenience.
			 )

    )

)

Link to comment
Share on other sites

  • 9 months later...

 

On a brighter note, I've complete everything else on knowledge is power, including the paypal side. If you have time, check it out at www.wolfcut.co.uk I'd really like to say thank you again for all your help..... onto Coffee Shop next :)

 

Armlocker, I was reading through your post and thought it was cool that you put your website link to a live example from the book, however I was a little bit let down when it linked to a Joomla site...What happened?  Did you give up on hand coding?  I used Joomla for years, the first install was always great.  But I found out that It took so much effort to maintain a Joomla site, sometimes I couldn't sleep at night thinking about it.  Especially when doing sites for other people.  I had finally just had enough.  Once I discovered Ullman's books, I've never looked back.  

Link to comment
Share on other sites

 Share

×
×
  • Create New...