Jump to content

Change Path


westair

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
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.