How upload my files in different directoy???

markosar200294

New Member
Messages
56
Reaction score
0
Points
0
I would like to upload my files in a different directory that html_plublic or tmp. I want to upload in a sub-directory html_plublic/materials. I am using PHP to upload but don´t let my upload files in a subdirectory, only in the html_plublic.
Can you help me?
Please.
 
Last edited:

VPmase

New Member
Messages
914
Reaction score
0
Points
0
Why don't you login to your CPanel and upload them from there? Go to your account panel and click Login to CPanel then when you log in find File Manager and use that.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
I'm not sure how you're uploading files to "public_html" with PHP, as uploaded files are stored in the directory specified by upload_tmp_dir or, failing that, the TMPDIR environment variable (which should be "/tmp"). From there, you can move it wherever you wish using move_uploaded_file. If you need any more than that, you need to show us a minimal code example.

Make sure you're not violating the X10 ToS. Free accounts aren't to be used for file hosting, nor are you to give others unfettered access. Restricting the upload directory means you're all right on the latter count, but I can't speak as to the former.
 

bdistler

Well-Known Member
Prime Account
Messages
3,534
Reaction score
196
Points
63
I would like to upload my files in a different directory that html_plublic or tmp. I want to upload in a sub-directory html_plublic/materials. I am using PHP to upload but don´t let my upload files in a subdirectory, only in the html_plublic.
Can you help me?
Please.

For a start what are the permissions set at for the sub-directory ?
what if any error do you receive ?
with what did you 'make' the sub-directory with ?
is a file of the same name already in the sub-directory ?
can you as a test upload to the sub-directory useing FTP ?

Tell us more and we can help you more
 

gomarc

Member
Messages
516
Reaction score
18
Points
18
Hi markosar200294,

I would like to upload my files in a different directory that html_plublic or tmp.

The secret is to move the uploaded file to your destination folder before the end of the script. PHP deletes the temporary upload after execution, so you just have to move it if you want to keep it. Doing it this way, allows you some control over what’s being uploaded.

Allowing users to upload files this way is easy but it opens very big security risk. Make sure only authorized users have access to it, and restrict as much as you can what is to be uploaded. Remember that you are the one responsible for what’s in your site.

For this example you will need to create 2 folders in your /public_html/

  • file_upload
  • materials

In the file_upload place this form.html code:

HTML:
<html>
<body>

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>

In the same folder create upload_file.php:

PHP:
<?php
//Set the path relative to script location
$destination_path = "../materials/";

//Some restrictions to the file upload
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists($destination_path . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      $destination_path . $_FILES["file"]["name"]);
      echo "Stored in: " . $destination_path . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>


Go to your browser and open http://www.batepapoworkshops.x10.mx/file_upload/form.html and upload a small gif image. It will end up on http://www.batepapoworkshops.x10.mx/materials/

Tested this on my free hosting (server: chopin) and it works with no problems.

Code source and more information: http://www.w3schools.com/php/php_file_upload.asp
 

markosar200294

New Member
Messages
56
Reaction score
0
Points
0
I´m very happy for your ideas, I´m thank you a lot of. I´ll try this and answer you as soon as possible.
Thank you again.
 
Top