westair Posted December 6, 2009 Share Posted December 6, 2009 Hi all complete novice here! I created a script upload.php that includes the path, $path1 = "./shop/Item/Description/"; I want to move upload.php from the root of the www to a newly created sub-directory (Admin) in www root. How do I change/specify the path to the same directory? Thanks Link to comment https://forums.phpfreaks.com/topic/184157-change-path/ Share on other sites More sharing options...
oni-kun Posted December 6, 2009 Share Posted December 6, 2009 Hi all complete novice here! I created a script upload.php that includes the path, $path1 = "./shop/Item/Description/"; I want to move upload.php from the root of the www to a newly created sub-directory (Admin) in www root. How do I change/specify the path to the same directory? Thanks Depends where "./shop/Item/Description/" is. But lets say it were root still. You'd use this: $path1 = "../shop/Item/Description/"; //Two dots = recurse one directory, out of admin to www then to /shop/... Or you can use an absolute path "domain.com/ship/item/description" But I assume you're going relative to preserve a cert.. Link to comment https://forums.phpfreaks.com/topic/184157-change-path/#findComment-972277 Share on other sites More sharing options...
westair Posted December 6, 2009 Author Share Posted December 6, 2009 Humm thanks for that. I had tried that but I receive an error, I assumed it was somthing to do with the path as it workes from the root fine. Guess the error must be something different. I receive the error: PHP Warning: move_uploaded_file(C:\inetpub\wwwroot\SpecialsAdmin../shop/Item/Brochures/Row1/Brochure.pdf): failed to open stream: No such file or directory in C:\inetpub\wwwroot\SpecialsAdmin\upload.php on line 33 PHP Warning: move_uploaded_file(): Unable to move 'C:\Windows\Temp\phpB998.tmp' to 'C:\inetpub\wwwroot\SpecialsAdmin../shop/Item/Brochures/Row1/Brochure.pdf' in C:\inetpub\wwwroot\SpecialsAdmin\upload.php on line 33 Below is the code. <?php $row = $_POST ['Chooserow']; $path1 = "../shop/Item/Description/"; $path2 = "../shop/Item/Price/"; $path3 = "../shop/Item/Brochures/"; $path4 = "../shop/Item/Images/"; $file1 = fopen( $path1 . $row . 'Description.txt', 'w', 1); fwrite($file1, $_POST['Description']); $file2 = fopen( $path2 . $row . 'Price.txt', 'w', 1); fwrite($file2, $_POST['Price']); // fclose($file1); //Check that we have a file if((!empty($_FILES["uploaded_image"])) && ($_FILES['uploaded_image']['error'] == 0) && (!empty($_FILES["uploaded_broch"])) && ($_FILES['uploaded_broch']['error'] == 0)) { //Check if the file is .pdf image and it's size is less than 400Kb $filename1 = basename($_FILES['uploaded_broch']['name']); $ext1 = substr($filename1, strrpos($filename1, '.') + 1); if (($ext1 == "pdf") && ($_FILES["uploaded_broch"]["type"] == "application/pdf") && ($_FILES["uploaded_broch"]["size"] < 400000)) { //Check if the file is a JPEG or GIF image and it's size is less than 10Kb $filename2 = basename($_FILES['uploaded_image']['name']); $ext2 = substr($filename2, strrpos($filename2, '.') + 1); if (($ext2 == "jpg") && ($_FILES["uploaded_image"]["type"] == "image/jpeg") || ($ext2 == "gif") && ($_FILES["uploaded_image"]["type"] == "image/gif") && ($_FILES["uploaded_image"]["size"] < 10000)) { //Determine the path to which we want to save this file $newname1 = dirname(__FILE__).$path3.$row.'Brochure.'.$ext1; $newname2 = dirname(__FILE__).$path4.$row.'Image.'.$ext2; //Check if the file with the same name is already exists on the server if (!file_exists($newname1) && ($newname2)){ //Attempt to move the uploaded file to it's new place if ((move_uploaded_file($_FILES['uploaded_broch'['tmp_name'],$newname1)) && (move_uploaded_file($_FILES['uploaded_image']['tmp_name'],$newname2))) { echo "It's done! The upload has been made to: ".$row; } else { echo "Error: A problem occurred during file upload!"; } } else { echo "Error: Data Exists in this Row"; } } else { echo "Error: Only .jpg or .gif images under 350Kb are accepted for upload"; } } else { echo "Error: Only Brochoure in .pdf format under 350Kb are accepted for upload"; } } else { echo "Error: No file uploaded"; } ?> (Sorry the paste didn't work well with the code) Thaks if you able to help Link to comment https://forums.phpfreaks.com/topic/184157-change-path/#findComment-972291 Share on other sites More sharing options...
PFMaBiSmAd Posted December 6, 2009 Share Posted December 6, 2009 Read the error - No such file or directory Unable to move 'C:\Windows\Temp\phpB998.tmp' to 'C:\inetpub\wwwroot\SpecialsAdmin../shop/Item/Brochures/Row1/Brochure.pdf Does C:\inetpub\wwwroot\SpecialsAdmin../shop/Item/Brochures/Row1/Brochure.pdf look like a correctly formed and valid path statement? Link to comment https://forums.phpfreaks.com/topic/184157-change-path/#findComment-972294 Share on other sites More sharing options...
oni-kun Posted December 6, 2009 Share Posted December 6, 2009 I wasn't aware you were running a Windows server. Simply change it to a backslash, such as "..\shop\" and it should work! <?php $row = $_POST ['Chooserow']; $path1 = "\..\shop\Item\Description\"; $path2 = "\..\shop\Item\Price\"; $path3 = "\..\shop\Item\Brochures\"; $path4 = "\..\shop\Item\Images\"; EDIT: "\SpecialsAdmin../shop/", you need another slash at the beginning than to make it valid. Such as my code up there. Link to comment https://forums.phpfreaks.com/topic/184157-change-path/#findComment-972295 Share on other sites More sharing options...
PFMaBiSmAd Posted December 6, 2009 Share Posted December 6, 2009 Under Windows, php converts each / to a \ before passing the command to the operating system. The issue is a missing / before the .. Link to comment https://forums.phpfreaks.com/topic/184157-change-path/#findComment-972296 Share on other sites More sharing options...
oni-kun Posted December 6, 2009 Share Posted December 6, 2009 Under Windows, php converts each / to a \ before passing the command to the operating system. The issue is a missing / before the .. Caught it same time as you, I noticed it when I looked again. Link to comment https://forums.phpfreaks.com/topic/184157-change-path/#findComment-972297 Share on other sites More sharing options...
westair Posted December 6, 2009 Author Share Posted December 6, 2009 Ok as I stated in the beginning, complete novice.. So you are saying $path1 = "../shop/Item/Description/"; Should change to? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/184157-change-path/#findComment-972301 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.