I am trying to upload some files using php and I am getting inconsistent errors. Everything works if I upload one or two files. When I try to upload three file the code breaks, but not all the time. 1/30 plus tries it will work. I have no idea what is going on.
This is forum/Html
Code: Select all
<html>
<?php
function display_themes_in_drop_down($path ){
//Strip The Underscore Out
$things_to_replace="/_/";
$replace_with=' ';
// Open the folder
$dir_handle = opendir($path) or die("Unable to open $path");
// Loop through the files
while ($file = readdir($dir_handle)) {
if ($file !='..' && $file !='.'){
//echo "$file<br>";
$file= preg_replace ($things_to_replace, $replace_with ,$file);
echo '<option>'.$file.'</option>';
}
}
// Close
closedir($dir_handle);
}
?>
<HEAD>
<SCRIPT language="JavaScript" SRC="../js/form_validation.js"></SCRIPT>
</HEAD>
<title>:::Upload Your Image:::</title>
<body>
<!--<form enctype="multipart/form-data" name="stuff_to_upload" action="" onsubmit="return check_if_theme_exist (this);" method="post">-->
<form enctype="multipart/form-data" name="stuff_to_upload" action="create_del_folders.php" onsubmit="return check_if_theme_exist (this);" method="post">
<!--<form name="stuff_to_upload" onsubmit="return check_if_theme_exist (this);" method="post">-->
Choose a topic to upload to Or Create a topic to upload to<br> <br>
<select name="preview_themes" onChange = "limit_one_theme_only(this)">
<option>Choose a theme</option>
<?php display_themes_in_drop_down ("../photos");?>
</select>
<input type="text" size = "20" name="create_this_folder" onKeyPress = "limit_one_theme_only_1(this)"/> <br><br>
Choose files to upload:
<br><br>
<input type="hidden" name="MAX_FILE_SIZE" value="10240000" />
Downloadable<input type="checkbox" name="dl[]">
<select name="experation[]">
<!--<option>-------------------</option>-->
<option>One Month</option>
<option>Two Months</option>
<option>Forever</option>
</select>
<input name="uploadedfile[]" type="file" />
<!-- Signature Photo<input type="checkbox" name="signature0" value="true"> -->
Color <input type="radio" name="borc0" value="c" >
B/W <input type="radio" name="borc0" value="b">
<br>
Downloadable<input type="checkbox" name="dl[]">
<select name="experation[]">
<!--<option>-------------------</option>-->
<option>One Month</option>
<option>Two Months</option>
<option>Never</option>
</select>
<input name="uploadedfile[]" type="file" />
<!-- Signature Photo<input type="checkbox" name="signature1" value="true"> -->
Color <input type="radio" name="borc1" value="c" >
B/W <input type="radio" name="borc1" value="b">
<br>
Downloadable<input type="checkbox" name="dl[]">
<select name="experation[]">
<!--<option>-------------------</option>-->
<option>One Month</option>
<option>Two Months</option>
<option>Never</option>
</select>
<input name="uploadedfile[]" type="file"/>
<!-- Signature Photo<input type="checkbox" name="signature2" value="true"> -->
Color <input type="radio" name="borc2" value="c" >
B/W <input type="radio" name="borc2" value="b">
<br><br>
<input type = "submit" value="Upload File"/>
</form>
</body>
</html>
Code: Select all
<?php
var_dump($_FILES, $_POST);
//var_dump($_FILES);
echo "<br><br>---------------------------------------------------- <br><br>";
$things_to_replace="/\s/";
$replace_with='_';
$path_of_folder=preg_replace ($things_to_replace, $replace_with ,$_POST["create_this_folder"]);
//Cleanup work because of IE 6
if (strlen($path_of_folder)!=0){
if ($path_of_folder[0]=='_'){
$path_of_folder=substr ($path_of_folder,1);
}
}
if (strlen($_POST["create_this_folder"]) == 0){
echo strlen($_POST["create_this_folder"])." << the length of form field create_this_folder <br>";
echo "lllloookkk <br>";
for ($i=0; $i<3; $i++){
echo $_FILES ['uploadedfile']['tmp_name'][$i]." << temp name <br>";
echo $_FILES ['uploadedfile']['name'][$i]." << original name <br>";
echo $_FILES ['uploadedfile']['type'][$i]." << type <br>";
echo $_FILES ['uploadedfile']['size'][$i]." << size<br>";
}
}
?>
This the output of var_dump($_FILES, $_POST); when I upload two files.
Code: Select all
array(1) { ["uploadedfile"]=> array(5) { ["name"]=> array(3) { [0]=> string(12) "DSC_0500.JPG" [1]=> string(12) "DSC_0624.JPG" [2]=> string(0) "" } ["type"]=> array(3) { [0]=> string(10) "image/jpeg" [1]=> string(10) "image/jpeg" [2]=> string(0) "" } ["tmp_name"]=> array(3) { [0]=> string(80) "C:\Documents and Settings\Administrator\Local Settings\Temp\PHP\upload\phpDB.tmp" [1]=> string(80) "C:\Documents and Settings\Administrator\Local Settings\Temp\PHP\upload\phpDC.tmp" [2]=> string(0) "" } ["error"]=> array(3) { [0]=> int(0) [1]=> int(0) [2]=> int(4) } ["size"]=> array(3) { [0]=> int(2376919) [1]=> int(3448569) [2]=> int(0) } } } array(4) { ["preview_themes"]=> string(3) "dsl" ["create_this_folder"]=> string(0) "" ["MAX_FILE_SIZE"]=> string(8) "10240000" ["experation"]=> array(3) { [0]=> string(9) "One Month" [1]=> string(9) "One Month" [2]=> string(9) "One Month" } }
----------------------------------------------------
0 << the length of form field create_this_folder
lllloookkk
C:\Documents and Settings\Administrator\Local Settings\Temp\PHP\upload\phpDB.tmp << temp name
DSC_0500.JPG << original name
image/jpeg << type
2376919 << size
C:\Documents and Settings\Administrator\Local Settings\Temp\PHP\upload\phpDC.tmp << temp name
DSC_0624.JPG << original name
image/jpeg << type
3448569 << size
<< temp name
<< original name
<< type
0 << size
Code: Select all
array(0) { } array(0) { }
----------------------------------------------------
Notice: Undefined index: create_this_folder in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 13
Notice: Undefined index: create_this_folder in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 22
Notice: Undefined index: create_this_folder in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 23
0 << the length of form field create_this_folder
lllloookkk
Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 28
<< temp name
Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 29
<< original name
Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 30
<< type
Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 31
<< size
Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 28
<< temp name
Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 29
<< original name
Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 30
<< type
Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 31
<< size
Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 28
<< temp name
Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 29
<< original name
Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 30
<< type
Notice: Undefined index: uploadedfile in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php_study\manipulate_image\php_code\create_del_folders.php on line 31
<< size
Thanks, Lindylex
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: