473,287 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Need help with file upload

Hello!
I again need your help, just can't understand whats going on.
Got this upload pictures form and it's having problem handling large
files (~1.5 - 2 MB).
Everything works fine if i just upload files, like this:

copy ($myfile, $uploadfolder . "/" . $myfile_name);

Everything works fine, it can process large files and everything,
but i need to make sure that people only upload pictures, so i change
it to this:

$fext = strrchr($myfile_name,".");
if($fext==".jpg" || $fext==".jpeg")
{
copy ($myfile, $uploadfolder . "/" . $myfile_name);
}

After this modification it can only process relatively small files,
around 200-300 kb, everytime i try to upload a large file it just does
not do anything,
it looks like the file is being uploaded and then nothing, the file is
not there...
I tried setting
set_time_limit(0);
but it did not change anything...
if i check the extension it does not upload large files, if i don't -
it does...
Could someone help me please, thank you!

P.S. Whats better to use, copy or move_uploaded_file? Or it just does
not matter?
Thanks a lot again!
Jul 17 '05 #1
4 2862
Tihon wrote:
Hello!
I again need your help, just can't understand whats going on.
Got this upload pictures form and it's having problem handling large
files (~1.5 - 2 MB).
Everything works fine if i just upload files, like this:

copy ($myfile, $uploadfolder . "/" . $myfile_name);

Everything works fine, it can process large files and everything,
but i need to make sure that people only upload pictures, so i change
it to this:

$fext = strrchr($myfile_name,".");
if($fext==".jpg" || $fext==".jpeg")
{
copy ($myfile, $uploadfolder . "/" . $myfile_name);
}

After this modification it can only process relatively small files,
around 200-300 kb, everytime i try to upload a large file it just does
not do anything,
it looks like the file is being uploaded and then nothing, the file is
not there...
I tried setting
set_time_limit(0);
but it did not change anything...
if i check the extension it does not upload large files, if i don't -
it does...
Could someone help me please, thank you!

P.S. Whats better to use, copy or move_uploaded_file? Or it just does
not matter?
Thanks a lot again!


Maybe you have some upload limit set on your server. Check your php.ini
file.
Jul 17 '05 #2
Tihon wrote:

Hello!
I again need your help, just can't understand whats going on.
Got this upload pictures form and it's having problem handling large
files (~1.5 - 2 MB).
Everything works fine if i just upload files, like this:

copy ($myfile, $uploadfolder . "/" . $myfile_name);

Everything works fine, it can process large files and everything,
but i need to make sure that people only upload pictures, so i change
it to this:

$fext = strrchr($myfile_name,".");
if($fext==".jpg" || $fext==".jpeg")
{
copy ($myfile, $uploadfolder . "/" . $myfile_name);
}


Have you considered CaSe SenSITivity? I'd try something like:

preg_match("/(jpeg|jpg)$/i", $_FILES['myfile']['name']);

Regards,
Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #3
Try this

upload.php
--------
<?
/* Max filesize: */
if($arquivo_size > 1024000) {
print "<SCRIPT> alert('File cannot to be larger than 1 Mb');
window.history.go(-1); </SCRIPT>\n";
exit;
}
/* Define target dir to store uploaded files */
if (!empty($arquivo) and is_file($arquivo)) {
$caminho="/full/path/to/the/dir/";
$caminho=$caminho.$arquivo_name;
/* Define the kind of file allowed */
if ((eregi(".DOC$", $arquivo_name)) || (eregi(".zip$",
$arquivo_name))){
copy($arquivo,$caminho);
print "<h1><center>File was sent!</center></h1>";
}
else{
print "<h1><center>File was not sent!</center></h1>";
print "<h2><font color='#FF0000'><center>File type not
allowed!</center></font></h2>";
}
}
?>

--------
upload.html

<html>
<head>
<script language="JavaScript">
<!--
function teste(){
if (document.upload.arquivo.value=="") {
alert("Arquivo para upload não informado!")
document.upload.arquivo.focus()
return false
}
}
//-->
</script>
</head>
<body>
<h2>Upload Simples</h2><br>
<form name="upload" action="upload.php" method="post"
enctype="multipart/form-data" onsubmit="return teste()">
<input type="file" name="arquivo" size="60"><br>
<br>
<input type="submit" name="enviar" value="Upload!">
</form>
</center>
</body>
</html>

=============

[]

Carlos

ti***@ziplip.com (Tihon) wrote in message news:<7d**************************@posting.google. com>...
Hello!
I again need your help, just can't understand whats going on.
Got this upload pictures form and it's having problem handling large
files (~1.5 - 2 MB).
Everything works fine if i just upload files, like this:

copy ($myfile, $uploadfolder . "/" . $myfile_name);

Everything works fine, it can process large files and everything,
but i need to make sure that people only upload pictures, so i change
it to this:

$fext = strrchr($myfile_name,".");
if($fext==".jpg" || $fext==".jpeg")
{
copy ($myfile, $uploadfolder . "/" . $myfile_name);
}

After this modification it can only process relatively small files,
around 200-300 kb, everytime i try to upload a large file it just does
not do anything,
it looks like the file is being uploaded and then nothing, the file is
not there...
I tried setting
set_time_limit(0);
but it did not change anything...
if i check the extension it does not upload large files, if i don't -
it does...
Could someone help me please, thank you!

P.S. Whats better to use, copy or move_uploaded_file? Or it just does
not matter?
Thanks a lot again!

Jul 17 '05 #4
ar****@hotmail.com (Carlos Marangon) wrote in message news:<2c*************************@posting.google.c om>...
Try this

upload.php
--------
<?
/* Max filesize: */
if($arquivo_size > 1024000) {
print "<SCRIPT> alert('File cannot to be larger than 1 Mb');
window.history.go(-1); </SCRIPT>\n";
exit;
}
/* Define target dir to store uploaded files */
if (!empty($arquivo) and is_file($arquivo)) {
$caminho="/full/path/to/the/dir/";
$caminho=$caminho.$arquivo_name;
/* Define the kind of file allowed */
if ((eregi(".DOC$", $arquivo_name)) || (eregi(".zip$",
$arquivo_name))){
copy($arquivo,$caminho);
print "<h1><center>File was sent!</center></h1>";
}
else{
print "<h1><center>File was not sent!</center></h1>";
print "<h2><font color='#FF0000'><center>File type not
allowed!</center></font></h2>";
}
}
?>

--------
upload.html

<html>
<head>
<script language="JavaScript">
<!--
function teste(){
if (document.upload.arquivo.value=="") {
alert("Arquivo para upload não informado!")
document.upload.arquivo.focus()
return false
}
}
//-->
</script>
</head>
<body>
<h2>Upload Simples</h2><br>
<form name="upload" action="upload.php" method="post"
enctype="multipart/form-data" onsubmit="return teste()">
<input type="file" name="arquivo" size="60"><br>
<br>
<input type="submit" name="enviar" value="Upload!">
</form>
</center>
</body>
</html>

=============

[]

Carlos


Thank you so very much Carlos!
I still don't understand why but your version works, uploads any size i want!
Must be the way you check for file extension,
Thank you very much!
Jul 17 '05 #5

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

Similar topics

2
by: Sean Dotson | last post by:
I have a form that passes variables to an asp file and then uploads a file. For some reason the request.form is not getting the info from the form. It's returning blanks. Any insight would be...
1
by: Rizwan | last post by:
I am writing this code for file upload in asp 3.0 on my webpage........ It is working on local system but when i want to upload an image on my website from client machine it is not working ..........
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
2
by: pbd22 | last post by:
Hi. I am getting the error: "Thread is running or terminated. It cannot restart." It is happening inside a file upload loop where a thread is created for each file (reporting bytes). After the...
3
by: Milagro | last post by:
Hello Everyone, I'm trying to debug someone elses php code. I'm actually a Perl programmer, with OO experience, but not in php. The code is supposed to upload a photo from a form and save it...
4
by: AshishMishra16 | last post by:
HI friends, I am using the Flex to upload files to server. I m getting all the details about the file, but I m not able to upload it to Server. Here is the code i m using for both flex & for...
2
by: pbd22 | last post by:
Hi. I have been wrestling with a problem for over a week now and I think I need to breathe and rethink my approach. I am wondering if somebody wouldn't mind telling me how they would tackle...
6
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.
2
by: beary | last post by:
Hello everyone, I posted this in unix/linux but it received no replies, so I assume it was the wrong forum. I'm trying here. I'm in way over my head with file permissions. The directory and...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.