Reputation: 764
I'm trying to upload a file by selecting it with an html form then sending it to the php to do the actual upload and storing on the server. But when I test it I get a completely blank error so I can't figure out what's wrong.
here's the html:
<form action="libs/sc.php" method="post" enctype="multipart/form-data" >
<input type="file" name="c_img1" tabindex="0" />
<input type="file" name="c_img2" tabindex="1" />
<input type="file" name="c_img3" tabindex="2" />
<input type="file" name="c_img4" tabindex="3" />
<input type="file" name="c_img5" tabindex="4" />
<input type="submit" />
</form>
and the php:
for($i = 1; $i <= 5; $i++) {
if(!move_uploaded_file($_FILES["c_img$i"]["tmp_name"],"../images/cards/".$i)) {
die('File Error: ' . $_FILES['c_img'.$i]['error'] . '<br />');
}
else
echo 'added' .$i;
}
and what happens when I run:
Array (
[c_img1] => Array (
[name] => 010_10 (2).JPG
[type] => image/jpeg
[tmp_name] => C:\Windows\Temp\php21CD.tmp
[error] => 0
[size] => 1080763
)
[c_img2] => Array (
[name] => 011_11 (2).JPG
[type] => image/jpeg
[tmp_name] => C:\Windows\Temp\php2383.tmp
[error] => 0
[size] => 612926
)
[c_img3] => Array (
[name] => 014_14 (2).JPG
[type] => image/jpeg
[tmp_name] => C:\Windows\Temp\php247E.tmp
[error] => 0
[size] => 975170
)
[c_img4] => Array (
[name] => 015_15 (2).JPG
[type] => image/jpeg
[tmp_name] => C:\Windows\Temp\php2616.tmp
[error] => 0
[size] => 1180438
)
[c_img5] => Array (
[name] => 016_16 (2).JPG
[type] => image/jpeg
[tmp_name] => C:\Windows\Temp\php27FB.tmp
[error] => 0
[size] => 1142986
)
)
Warning: move_uploaded_file(../images/cards/356): failed to open stream: No such file or directory in C:\Apache2\htdocs\test\libs\sc.php on line 26 Warning: move_uploaded_file(): Unable to move 'C:\Windows\Temp\php21CD.tmp' to '../images/cards/356' in C:\Apache2\htdocs\test\libs\sc.php on line 26 File Error: 0
Upvotes: 0
Views: 704
Reputation: 82028
First, you should use move_uploaded_file
to move uploaded files. Second, (Turned out that this was inaccurate)$_FILES['c_img'.$i]["temp_name"]
, if I remember correctly, is an array, which means you need to access it: $_FILES['c_img'.$i]["temp_name"][0];
.
is_dir('../images/cards/');
.jpg
or you can use pathinfo
to grab the extension from $_FILES['c_img'.$i]["name"];
Upvotes: 1