473,385 Members | 1,487 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,385 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 2884
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.