By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,793 Members | 1,257 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,793 IT Pros & Developers. It's quick & easy.

Need help with file upload

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.