Jump to content

[SOLVED] mkdir - possible to make a directory outside of the folder the script is in?


Recommended Posts

Hey

My file structure is as follows

 

Site\

    Images\

              Large_product_image

              Small_product_image

    Includes\

    Scripts\

 

Im trying to use mkdir in a script that is within the scripts folder. The directory im trying to create is Images\Small_product_image\$prod_id.

Here is the script to make the directory

 

<?php
mkdir("\Images\small_product_image\$prod_id");
copy($_FILES['$thumb'], "/Images/small_product_image/$prod_id/$thumb");
?>

I've tried mulitple combinations (as in file paths) but keep getting file exsist error.

can create a folder with in the same folder the script is in fine.

 

Any help would be great, thanks

 

   

You're using an absolute file path there which means it'd be at /root/images instead of your website's root directory.  Also, you can only create folders that apache has access to edit.  Try using relative paths, and if that doesn't work, check permissions.

<?php
mkdir("../Images/small_product_image/$prod_id");
copy($_FILES['$thumb'], "/Images/small_product_image/$prod_id/$thumb");
?>

 

use rename() to physically move files, unless you want to make a duplicate..

Hey

Thanks that works great sorry for taking awhile to reply had to look up the diffrence betwenn relative paths and absolute i had a general idea but didnt know about things like the '..' to move up a directory. thanks

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.