473,783 Members | 2,564 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File upload from a form / upload_tmp_dir query

Hi Everyone

This is my first day with PHP and, not surprisingly, I've run into a problem
:-)

I want to allow file uploads to the server without exposing the
non-technical end-users to FTP settings, file naming protocols, etc. I've
found the following from http://www.zend.com/manual/features.file-upload.php
....

HTML FILE (uploadtest.htm l)

<form enctype="multip art/form-data" action="uploadt est.asp" method="POST">
Send this file: <input name="userfile" type="file">
<input type="submit" value="Send File">
</form>

PHP FILE (uploadtest.php )

<?php
// In PHP earlier then 4.1.0, $HTTP_POST_FILE S should be used instead of
// $_FILES. In PHP earlier then 4.0.3, use copy() and is_uploaded_fil e()
// instead of move_uploaded_f ile

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir. $_FILES['userfile']['name'];

print "<pre>";
if (move_uploaded_ file($_FILES['userfile']['tmp_name'], $uploadfile)) {
print "File is valid, and was successfully uploaded. ";
print "Here's some more debugging info:\n";
print_r($_FILES );
} else {
print "Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES );
}
print "</pre>";
?>

END OF CODE

I select a file to upload and the delay in submitting the form suggests that
the file has been sent. But I always get the "possible file upload attack"
result. The file info shows the correct filename and type but the filesize
is always '0' and the 'tmp_name' is always 'none'.

Assuming this was the problem I did some digging using phpinfo(). The
version is 4.1.2 so I seem to be using the right commands as per the
instructions with the code. But the 'upload_tmp_dir ' variable is NOT SET
which I think might be the problem.

So, with apologies for taking so long to get here, I have two queries...

1) Is there anything wrong with the code I'm using?
2) Where do uploaded files go if 'upload_tmp_dir ' is not set and how can I
bypass this without access to the server (shared hosting)?

Any help would be appreciated.

Many thanks

Tim.

--
My real e-mail address is tim218 before the at followed by supermail.org.u k.
Jul 16 '05 #1
4 6754
Sorry the form action should be uploadtest.php not uploadtest.asp (still
getting the bad M$ habits out of my head!!).

Tim.

--
My real e-mail address is tim218 before the at followed by supermail.org.u k.

"Tim218" <se***********@ for.email.addre ss.invalid> wrote in message
news:bj******** **@hercules.bti nternet.com...
Hi Everyone

This is my first day with PHP and, not surprisingly, I've run into a problem :-)

I want to allow file uploads to the server without exposing the
non-technical end-users to FTP settings, file naming protocols, etc. I've
found the following from http://www.zend.com/manual/features.file-upload.php ...

HTML FILE (uploadtest.htm l)

<form enctype="multip art/form-data" action="uploadt est.asp" method="POST">
Send this file: <input name="userfile" type="file">
<input type="submit" value="Send File">
</form>

PHP FILE (uploadtest.php )

<?php
// In PHP earlier then 4.1.0, $HTTP_POST_FILE S should be used instead of
// $_FILES. In PHP earlier then 4.0.3, use copy() and is_uploaded_fil e()
// instead of move_uploaded_f ile

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir. $_FILES['userfile']['name'];

print "<pre>";
if (move_uploaded_ file($_FILES['userfile']['tmp_name'], $uploadfile)) {
print "File is valid, and was successfully uploaded. ";
print "Here's some more debugging info:\n";
print_r($_FILES );
} else {
print "Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES );
}
print "</pre>";
?>

END OF CODE

I select a file to upload and the delay in submitting the form suggests that the file has been sent. But I always get the "possible file upload attack" result. The file info shows the correct filename and type but the filesize is always '0' and the 'tmp_name' is always 'none'.

Assuming this was the problem I did some digging using phpinfo(). The
version is 4.1.2 so I seem to be using the right commands as per the
instructions with the code. But the 'upload_tmp_dir ' variable is NOT SET
which I think might be the problem.

So, with apologies for taking so long to get here, I have two queries...

1) Is there anything wrong with the code I'm using?
2) Where do uploaded files go if 'upload_tmp_dir ' is not set and how can I
bypass this without access to the server (shared hosting)?

Any help would be appreciated.

Many thanks

Tim.

--
My real e-mail address is tim218 before the at followed by supermail.org.u k.

Jul 16 '05 #2
Hi Everyone

I've now solved the problem.

Many thanks

Tim.

--
My real e-mail address is tim218 before the at followed by supermail.org.u k.

"Tim218" <se***********@ for.email.addre ss.invalid> wrote in message
news:bj******** **@hercules.bti nternet.com...
Sorry the form action should be uploadtest.php not uploadtest.asp (still
getting the bad M$ habits out of my head!!).

Tim.

--
My real e-mail address is tim218 before the at followed by supermail.org.u k.
"Tim218" <se***********@ for.email.addre ss.invalid> wrote in message
news:bj******** **@hercules.bti nternet.com...
Hi Everyone

This is my first day with PHP and, not surprisingly, I've run into a

problem
:-)

I want to allow file uploads to the server without exposing the
non-technical end-users to FTP settings, file naming protocols, etc. I've found the following from

http://www.zend.com/manual/features.file-upload.php
...

HTML FILE (uploadtest.htm l)

<form enctype="multip art/form-data" action="uploadt est.asp" method="POST"> Send this file: <input name="userfile" type="file">
<input type="submit" value="Send File">
</form>

PHP FILE (uploadtest.php )

<?php
// In PHP earlier then 4.1.0, $HTTP_POST_FILE S should be used instead of
// $_FILES. In PHP earlier then 4.0.3, use copy() and is_uploaded_fil e() // instead of move_uploaded_f ile

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir. $_FILES['userfile']['name'];

print "<pre>";
if (move_uploaded_ file($_FILES['userfile']['tmp_name'], $uploadfile)) {
print "File is valid, and was successfully uploaded. ";
print "Here's some more debugging info:\n";
print_r($_FILES );
} else {
print "Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES );
}
print "</pre>";
?>

END OF CODE

I select a file to upload and the delay in submitting the form suggests

that
the file has been sent. But I always get the "possible file upload

attack"
result. The file info shows the correct filename and type but the

filesize
is always '0' and the 'tmp_name' is always 'none'.

Assuming this was the problem I did some digging using phpinfo(). The
version is 4.1.2 so I seem to be using the right commands as per the
instructions with the code. But the 'upload_tmp_dir ' variable is NOT SET which I think might be the problem.

So, with apologies for taking so long to get here, I have two queries...

1) Is there anything wrong with the code I'm using?
2) Where do uploaded files go if 'upload_tmp_dir ' is not set and how can I bypass this without access to the server (shared hosting)?

Any help would be appreciated.

Many thanks

Tim.

--
My real e-mail address is tim218 before the at followed by

supermail.org.u k.


Jul 16 '05 #3
Also sprach Tim218:
Hi Everyone
Hi Tim,
I've now solved the problem.
Would you be so kind as to let us in on the details of your solution?
Many thanks


You're welcome. :-)

Jul 16 '05 #4
Hi

I'm afraid I couldn't resolve the PHP problem which I think was caused by
the temporary directory setting on the server not being set (I don't have
admin control over the server).

On this occasion I went back to an ASP solution which had been my original
plan. The phpinfo() function proved useful as it let me know the server was
running Chili!ASP and once I knew this I was able to find details of its
built-in file upload function.

But my brief introduction to PHP has convinced me that it is the way forward
and that my first major ASP project should be my last. So hopefully I will
see you all in here again soon.

Best wishes

Tim.

--
My real e-mail address is tim218 before the at followed by supermail.org.u k.

"Thomas Mlynarczyk" <bl************ *@hotmail.com> wrote in message
news:bj******** *****@news.t-online.com...
Also sprach Tim218:
Hi Everyone


Hi Tim,
I've now solved the problem.


Would you be so kind as to let us in on the details of your solution?
Many thanks


You're welcome. :-)


Jul 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6095
by: Leigh Riley | last post by:
My PHP.ini file sets the following: file_uploads = on upload_max_filesize = 3M upload_tmp_dir = /tmp When I try and upload the file, it doesn't appears in /tmp. The name of the Submit button is userFile. On the processing page, I echo $userFile and it gives "/tmp/phpjXJ1ZK". However, the following
3
2189
by: Mike Walsh | last post by:
I have a problem uploading files with PHP which has me stumped! I am unable to successfully upload files. My simple test script is as follows: <?php if (count($_FILES)) { var_dump($_FILES) ; }
9
2377
by: R. Rajesh Jeba Anbiah | last post by:
Q: How should I handle file upload? A: File uploading requires HTML form of content type "multipart/form-data". The file content has to be POSTed/submitted via the form and once the file is uploaded, it will be available at the "upload_tmp_dir" (usually /tmp) directory. Then you may move that file to another directory using move_uploaded_file(); file name will be available in the superglobal $_FILES. Refer:...
6
3042
by: Vic Spainhower | last post by:
Hello, I am trying to do a FTP file upload which works fine on my localhost but on my ISP server it fails. I can't seem to find where I can go to find the specific cause of the failure. In both cases the file is being transmitted to the same FTP server and using the same PHP script so it shouldn't be a file size or login credentials problem. Could someone please help me out and give me some ideas what is wrong. I would really...
9
3204
by: Arthur Jacobs | last post by:
Good Day, I can upload a file as long as it is empty (thanks Hendri Kurniawan). I do not know where to look. Can someone help me understand what I need to do to upload a small image. http://chops.novatrope.com/game/test/upload_file3.php Here is some more info http://chops.novatrope.com/info.php
4
12624
by: lawrence k | last post by:
I've a file that starts like this: <form id="pdsForm" method="post" action="/mcControlPanel.php" class="mcForm" charset="UTF-8" enctype="multipart/form-data" > and it contains this input: <input id="biopic" name="biopic" type="file" />
1
3161
by: wbsurfver | last post by:
I'm trying to figure out why I can't upload a file in php. I'm trying it locally on a windows XP machine running Apache 2.2 and PHP 5.2.1. That is I am running the browser/server on same machine to test with. I also tried it on a remote linux server, though in that case I'm not sure what the s config settings where, except that it does have PHP and I get the same results. Are there any releevant apache settings ? I have not come...
6
4866
by: howa | last post by:
Suppose the file is stored in "upload_tmp_dir ", so why I need to increase the memory limit? If I want to upload 100 MB, how large should I set? Thanks.
24
7734
by: owz2008 | last post by:
This has probably been covered before but could not find a similar thread. Basically I have created a form which can be viewed at www.icomworks.co.uk/canvaspayform.html I want to submit the form along with the file so that they are both placed on my server... I have created a folder on my server in my public_html called myscripts and have saved my upload.cgi script into that folder. my form points to that script but when I fill in the...
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.