Jocky Posted April 19, 2011 Share Posted April 19, 2011 Hi Larry, I have a problem trying to upload a pdf file. I get the following error message: An error occurred in script '/mnt/vol3/home/b/e/bexcom/public_html/e-Commerce/kip/add_pdf.php' on line 52: move_uploaded_file(www.bexcomputersdesigns.co.uk/e-Commerce/pdfs/bd42c707f6a002d4abd8993fa08236eb5ca84e6a_tmp) [function.move-uploaded-file]: failed to open stream: No such file or directory This is the section (including the line numbers for reference) from the add_pdf.php file: 46 // If no errors, create file's new name and destination 47 if (!array_key_exists ('pdf', $add_pdf_errors)) { 48 $tmp_name = sha1 ($file['name'] . uniqid ('', true)); 49 $dest = PDFS_DIR . $tmp_name . '_tmp'; 50 51 // Move the file 52 if (move_uploaded_file ($file['tmp_name'], $dest)) { 53 $_SESSION['pdf']['tmp_name'] = $tmp_name; 54 $_SESSION['pdf']['size'] = $size; 55 $_SESSION['pdf']['file_name'] = $file['name']; 56 echo '<h4> 57 The file has been uploaded! 58 </h4>'; 59 } else { 60 trigger_error ('The file could not be moved.'); 61 unlink ($file['tmp_name']); 62 } 63 } // End of array_key_exists() IF. This is how I have set up the paths in my config.inc.php file: define ('BASE_URI','www.bexcomputersdesigns.co.uk/e-Commerce/'); define ('BASE_URL','www.bexcomputersdesigns.co.uk/'); define ('MYSQL','includes/mysql.inc.php'); define ('PDFS_DIR',BASE_URI . 'pdfs/'); All my files are within a folder called kip which this is within a folder called e-Commerce. I have placed the pdfs folder within the e-Commerce folder so it was outside the root directory. Hope this information helps. Link to comment Share on other sites More sharing options...
Jonathon Posted April 19, 2011 Share Posted April 19, 2011 I believe that you are missing 'kip' in this reference move_uploaded_file(www.bexcomputersdesigns.co.uk/e-Commerce/pdfs/bd42c707f6a002d4abd8993fa08236eb5ca84e6a_tmp? 1 Link to comment Share on other sites More sharing options...
Paul Swanson Posted April 19, 2011 Share Posted April 19, 2011 I don't think you want the domain name in the location to move the file to. PHP operates on the file system level when copying files. Try changing your PDFS_DIR constant definition to: define ('PDFS_DIR', $_SERVER['DOCUMENT_ROOT'] . '/e-Commerce/pdfs/'); www.bexcomputersdesigns.co.uk isn't a directory, it's a DNS entry; a friendly alias of the actual IP address. PHP doesn't use it, it wants something like /mnt/vol3/home/b/e/bexcom/public_html/e-Commerce/pdfs/. $_SERVER['DOCUMENT_ROOT'] will return the /mnt/vol3/home/b/e/bexcom/public_html part (I can't remember if it includes the trailing slash or not. 1 Link to comment Share on other sites More sharing options...
Jocky Posted April 19, 2011 Author Share Posted April 19, 2011 Thanks Paul. You are a life-saver. I changed the PDFS_DIR definition to how you described and it worked a treat. I have only been using PHP for a few months, so still learning a lot. Thanks again! Link to comment Share on other sites More sharing options...
Recommended Posts