FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


TMP File Problem





halilibo
I am using PHP file upload on my site, but can not access files. The script gets error.

Temp File name : /tmp/phpeaX... (something like this, always different.)
but i have no /tmp folder.

how can i set another tmp folder for my script.
i tried using ini_set() but it failed, php.net says upload_tmp_dir is PHP_INI_SYSTEM

Can you help about this?

Thanks a lot.
coreymanshack
halilibo wrote:
I am using PHP file upload on my site, but can not access files. The script gets error.

Temp File name : /tmp/phpeaX... (something like this, always different.)
but i have no /tmp folder.

how can i set another tmp folder for my script.
i tried using ini_set() but it failed, php.net says upload_tmp_dir is PHP_INI_SYSTEM

Can you help about this?

Thanks a lot.


Make sure proper permissions are set in CHMOD.
halilibo
If a had a /tmp folder, i would check its CHMOD, but i have not got a /tmp folder. My problem is that. I guess, the /tmp folder is for the whole server and i have no access to it.

I am asking that can i set my own tmp folder, like /home/halilibo/domains/blabla/public_html/tmp.
If possible, how?

I tried to make my own php.ini file, but failed.
I tried to use ini_set("upload_tmp_dir","/home/halilibo/domains/blabla/public_html/tmp");, it failed too.

Is there anyother way to do this?
coreymanshack
halilibo wrote:
If a had a /tmp folder, i would check its CHMOD, but i have not got a /tmp folder. My problem is that. I guess, the /tmp folder is for the whole server and i have no access to it.

I am asking that can i set my own tmp folder, like /home/halilibo/domains/blabla/public_html/tmp.
If possible, how?

I tried to make my own php.ini file, but failed.
I tried to use ini_set("upload_tmp_dir","/home/halilibo/domains/blabla/public_html/tmp");, it failed too.

Is there anyother way to do this?


I ment the chmod of your upload script. ini_set() is the only way I know of. What folder are you uploading the files to? You have to upload them somewhere they can't be floating in cyberspace.
halilibo
i am uploading my files to public_html/aio2/_upload folder.
but i think there is no problem with the uploading folder because i alerted the folder name and tempfile name. and i can not access the temp file, so do PHP.

here is my php.ini
Code:

upload_tmp_dir="/home/halilibo/domains/mydomain/tmp"


and here is my .htaccess
Code:

ErrorDocument 400 /error.php?no=400
ErrorDocument 401 /error.php?no=401
ErrorDocument 403 /error.php?no=403
ErrorDocument 404 /error.php?no=404
ErrorDocument 500 /error.php?no=500
php_flag upload_tmp_dir "/home/halilibo/domains/mydomain/tmp"
coreymanshack
halilibo wrote:
i am uploading my files to public_html/aio2/_upload folder.
but i think there is no problem with the uploading folder because i alerted the folder name and tempfile name. and i can not access the temp file, so do PHP.

here is my php.ini
Code:

upload_tmp_dir="/home/halilibo/domains/mydomain/tmp"


and here is my .htaccess
Code:

ErrorDocument 400 /error.php?no=400
ErrorDocument 401 /error.php?no=401
ErrorDocument 403 /error.php?no=403
ErrorDocument 404 /error.php?no=404
ErrorDocument 500 /error.php?no=500
php_flag upload_tmp_dir "/home/halilibo/domains/mydomain/tmp"


Can you also post your uploader script source? Thanks.
halilibo
Code:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?
if(isset($_FILES["file"]))
   {
   $name=$_FILES["file"]["name"];
   
   //file extension
   $ext=getext($name);
   
   //uniqe name
   $nm=date("Y-m-dhis.").$ext;
   if(move_uploaded_file("../_upload/$nm"))
      {
      switch(strtolower($ext))
         {
         //for mysql db records
         case "jpg":case "gif":case "bmp":case "png":case "jpeg":$tur="'image'";break;
         default: $tur="'file'";
         }
      }
   else
      {
?>
<script type="text/javascript">
   alert("Error on uploading. \nError Code: <?echo $_FILES["file"]["error"];?>\nTemporary Name: <?echo $_FILES["file"]["tmp_name"];?>");
</script>
<?
      }
   }
else
   {
?>
<script type="text/javascript">
   alert("No valid file.");
</script>
<?
   }
?>

this is my upload script.
but i have removed both php.ini, ini_set() function and .htaccess. Now my system is harmless Smile
coreymanshack
So you're good now? Very Happy

I don't like the way you put your script in the php, this is not good practice.
It makes it more difficult for others to read your programs and make sense of it.
When you start the bracket for your php program, it's also good practice to use <?php start bracket.

Code:
<script type="text/javascript">
   alert("No valid file.");
</script>


In my php programs I use a templating class.
halilibo
coreymanshack wrote:
So you're good now? Very Happy

I don't like the way you put your script in the php, this is not good practice.

Code:
<script type="text/javascript">
   alert("No valid file.");
</script>


In my php programs I use a templating class.


i haven't said i am good. If i thought that i am good i wouldnt be here and asking questions.

now, my problem, you know, i can not access the /tmp folder of server and i have to or i could set my own.

do you have any suggestions about setting a new tmp folder, or how to access the server /tmp folder. Thank you for your help. Smile
coreymanshack
halilibo wrote:
coreymanshack wrote:
So you're good now? Very Happy

I don't like the way you put your script in the php, this is not good practice.

Code:
<script type="text/javascript">
   alert("No valid file.");
</script>


In my php programs I use a templating class.


i haven't said i am good. If i thought that i am good i wouldnt be here and asking questions.

now, my problem, you know, i can not access the /tmp folder of server and i have to or i could set my own.

do you have any suggestions about setting a new tmp folder, or how to access the server /tmp folder. Thank you for your help. Smile


Oh I'm sorry I ment "are you good now" as in you do not have the problem anymore, because you said "my system is harmless". Sorry for that misunderstanding, I'm about to test your code. I'm at school though, so my next reply will probably take a few hours.

Hang in there dude, I got your back!
halilibo
I am so so sorry. Confused I have misunderstood you. Sorry again.

yes, i am good now Smile. But my system is as the same. the problem continues. Whatever i tried had no effect on my site.
coreymanshack
Through debugging your code I found that.

Code:
$_FILES["file"]


Does not exist.

Quote:
Fatal error: Call to undefined function getext() in /usr/home/coreyman/domains/techflash.frih.net/public_html/testing.php on line 8


getext(); is a function that does not exist by default in php.

I'll work on your code more in a little while.


EDIT: Figured out this stuff didn't work because they were specific to you.
halilibo
yes getext is my own function to get the extension of the file. it is located somewhere in upper folders (../_common i guess. i forgot where it was).
coreymanshack
I took your code down to a basic working peice.

Changes made,
1)Files you uploaded are named after the name of the uploaded file instead of the static name.
2)move_uploaded_file(); function takes two arguments, you only had one argument being passed
3)As I said before $_FILES["file"] does not exist so I completley removed this. (likely the html input name)


Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<?php 
   //choose path for file
   $target_path = "uploads/";
   //add name of file
   $target_path .= basename( $_FILES['uploadedfile']['name']);

   //uniqe name
   $nm=date("Y-m-dhis.").$ext;
   if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)){
      switch(strtolower($ext))
         {
         //for mysql db records
         case "jpg":case "gif":case "bmp":case "png":case "jpeg":$tur="'image'";break;
         default: $tur="'file'";
         }
      }
   else
      { //error       
     }
?>
<form enctype="multipart/form-data" action="/testing.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>


</body>
</html>


You should use this framework and edit it.
If you are having trouble getting this to work, give the proper permissions to this file, 755 might work, I hear 777 has secuirty issues but I think I used 777.
Also set permissions for the folder you are uploading the files to.

If you change it back to the naming convention you used, you will need to append $target_path with the name and remove this line
Code:
$target_path .= basename( $_FILES['uploadedfile']['name']);


I think it would look something like this
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<?php
   //choose path for file
   $target_path = "uploads/";

   //add name of file
   
   //set up file var
   $name = $_FILES['uploadedfile']['name'];
   //file extension
   $ext=getext($name);
   //uniqe name
   $target_path .=date("Y-m-dhis.").$ext;


   if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)){
      switch(strtolower($ext))
         {
         //for mysql db records
         case "jpg":case "gif":case "bmp":case "png":case "jpeg":$tur="'image'";break;
         default: $tur="'file'";
         }
      }
   else
      { //error       
     }
?>
<form enctype="multipart/form-data" action="/testing.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>


</body>
</html>



I think your initial problem was where you were only passing one variable to the move_uploaded_file() function. You did not add the tmp variable where the file was stored. The temporary variable for the file is $_FILES['uploadedfile']['tmp_name']
halilibo
i saw that in a forum, before that i had written my code as you said.
Code:

move_upload_file($_FILES["file"]["tmp_name"],"../_upload/".date("Y-m-dhis.").getext($name));
coreymanshack
halilibo wrote:
i saw that in a forum, before that i had written my code as you said.
Code:

move_upload_file($_FILES["file"]["tmp_name"],"../_upload/".date("Y-m-dhis.").getext($name));


So is everything working for you now? Can I get an update on your situation.
halilibo
not everything actually, i can not upload files via that script still.

and that is the problem. access to /tmp folder.
halilibo
not everything actually,still i can not upload files via that script .

and that is the problem. access to /tmp folder.

there is nothing wrong with the files or codes. because i used them before.
coreymanshack
halilibo wrote:
not everything actually,still i can not upload files via that script .

and that is the problem. access to /tmp folder.

there is nothing wrong with the files or codes. because i used them before.


You used
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<?php
   //choose path for file
   $target_path = "uploads/";
   //add name of file
   $target_path .= basename( $_FILES['uploadedfile']['name']);

   //uniqe name
   $nm=date("Y-m-dhis.").$ext;
   if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)){
      switch(strtolower($ext))
         {
         //for mysql db records
         case "jpg":case "gif":case "bmp":case "png":case "jpeg":$tur="'image'";break;
         default: $tur="'file'";
         }
      }
   else
      { //error       
     }
?>
<form enctype="multipart/form-data" action="/testing.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>


</body>
</html>


and it generated what error?
halilibo
Sorry, i think i can not explain my situation clearly.

I am writing a web site. All files and codes are running as they should. But i think due to server settings, i can not upload files via my site.

PHP saves the uploaded files to /tmp folder before moving it to the latest place with move_uploaded_file function.

And i can not access the /tmp folder. So i have two posibilities:

    1. I could find a way to access the /tmp folder.
    a. i may need the root privilages of the whole server for this, so forget this one.
    2. I could set/define my own /tmp folder.
    I tried

      a. ini_set() to set my own /tmp folder, (have not worked)
      b. php.ini file for the folder i run my script from, (have not worked)
      c. .htaccess for my account. (canceled my from postings, $_POST variable gone away. FIXED later.)



and now, i can find any other way to solve this problem. So, i wrote here.

And Thank you for everything, and trying to help me.
coreymanshack
halilibo wrote:
Sorry, i think i can not explain my situation clearly.

I am writing a web site. All files and codes are running as they should. But i think due to server settings, i can not upload files via my site.

PHP saves the uploaded files to /tmp folder before moving it to the latest place with move_uploaded_file function.

And i can not access the /tmp folder. So i have two posibilities:

    1. I could find a way to access the /tmp folder.
    a. i may need the root privilages of the whole server for this, so forget this one.
    2. I could set/define my own /tmp folder.
    I tried

      a. ini_set() to set my own /tmp folder, (have not worked)
      b. php.ini file for the folder i run my script from, (have not worked)
      c. .htaccess for my account. (canceled my from postings, $_POST variable gone away. FIXED later.)



and now, i can find any other way to solve this problem. So, i wrote here.

And Thank you for everything, and trying to help me.


I think I can not explain myself clearly, I asked what error the code generated.
halilibo
I think it worked, thanks a lot.
Thank you coreymanshack
coreymanshack
halilibo wrote:
I think it worked, thanks a lot.


NICE Very Happy
What ended up being the problem?
halilibo
coreymanshack wrote:
halilibo wrote:
I think it worked, thanks a lot.


NICE Very Happy
What ended up being the problem?


One wrong code Very Happy Thank you again. Tryin to fix this one for 3-4 days without any break.
coreymanshack
halilibo wrote:
coreymanshack wrote:
halilibo wrote:
I think it worked, thanks a lot.


NICE Very Happy
What ended up being the problem?


One wrong code Very Happy Thank you again. Tryin to fix this one for 3-4 days without any break.


No problem, that's what we're here for.
Related topics
Phoenix free PHP scripts
PHP index page not displaying problem
Page File problem with FireFox
Can't get Mambo installed
Problem with folder in ftp
Phpbb forum problems [wants account reset]
Joomla /tmp/ file.
NEED FORUM FIXED!
temporary internet files... problem
Hosting Problemss
Weird file problem :(
Upload image file problem
adding another domain that points to my frihost hosting
Flv file problem
Reply to topic    Frihost Forum Index -> Support and Web Hosting -> Web Hosting Support

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.