PHP file upload missing tmp_name - php

I downloaded and installed xampp for windows. When i try to upload pictures, video or music to my localhost in php i just get $_FILE['some_file'][name] i dont get [size], [type], [error] and most important to my [tmp_name]. But when i try to upload some .rar file or some document i get all these file informations. Here is what i get when i try to upload some music files:
Array
(
[name] => Array
(
[0] => Blondee – Moment (Original Mix) www.livingelectro.com.mp3
[1] => Eli & Fur – Turn The Lights Down www.livingelectro.com.mp3
[2] => Fake Forward Ft. CHRYSTAL - Brush It Off (Club Mix) www.livingelectro.com.mp3
)
[type] => Array
(
[0] =>
[1] =>
[2] =>
)
[tmp_name] => Array
(
[0] =>
[1] =>
[2] =>
)
[error] => Array
(
[0] => 1
[1] => 1
[2] => 1
)
[size] => Array
(
[0] => 0
[1] => 0
[2] => 0
)
)
[type] and [tmp_name] is empty and [error] shows errors and [size] shows 0kb.
But when i try to upload some rar files everithing is working:
Array
(
[name] => Array
(
[0] => Aaargh.zip
[1] => afta-sans.zip
[2] => armata.zip
)
[type] => Array
(
[0] => application/octet-stream
[1] => application/octet-stream
[2] => application/octet-stream
)
[tmp_name] => Array
(
[0] => C:\xampp\tmp\php95EE.tmp
[1] => C:\xampp\tmp\php95FF.tmp
[2] => C:\xampp\tmp\php9600.tmp
)
[error] => Array
(
[0] => 0
[1] => 0
[2] => 0
)
[size] => Array
(
[0] => 13835
[1] => 32570
[2] => 26454
)
)
Here is my index code:
<?php
$files = $_FILES["postFile"];
echo '<pre>';
print_r($files);
echo '</pre></br></br>';
?>

If you notice in the ones where you do not get all the array occurances filled you do get all the uploaded files flagged with errors!
[error] => Array
(
[0] => 1
[1] => 1
[2] => 1
)
1 = UPLOAD_ERR_INI_SIZE
That will be why none of the other fields contain what you expect.
You must always check the error array before doing anything with the uploaded files.
You need to check the php.ini file for this parameter and probably increase the max size.
upload_max_filesize = ?
And quite possibly this one too.
post_max_size = ?
The post_max_size will need to be large enough to cope with the upload_max_filesize * number of files uploaded + a few k to cope with other fields passed at the same time and general overhead.
......

Related

CodeIgniter Loses Images when Form Validates

I've got a multipart form that's set to accept multiple images from a single field, defined as follows:
echo form_upload('userfile[]', set_value('userfile[]'), 'multiple');
When I run a successful form (using CodeIgniter's built-in validator), it only uploads one image (the last one in the list).
Suspicious, I did a dump of the $_FILES global when the form validated, and it showed the following:
Array
(
[userfile] => Array
(
[name] => image_three.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phpZl6RHT
[error] => 0
[size] => 18236
)
)
If I go back and clear out any required field (it doesn't matter which), the same input shows the following in $_FILES:
Array
(
[userfile] => Array
(
[name] => Array
(
[0] => image_one.jpg
[1] => image_two.jpg
[2] => image_three.jpg
)
[type] => Array
(
[0] => image/jpeg
[1] => image/jpeg
[2] => image/jpeg
)
[tmp_name] => Array
(
[0] => /tmp/phpEFaVib
[1] => /tmp/phpkcXJmL
[2] => /tmp/phpoqcDql
)
[error] => Array
(
[0] => 0
[1] => 0
[2] => 0
)
[size] => Array
(
[0] => 43308
[1] => 60883
[2] => 18236
)
)
)
Based on the fact that the incomplete form registers all three images properly, I'm assuming that the form is defined properly, and that something in the validation engine is what's causing it. That said, my attempt to test that assumption by disabling all of the form validation code returned the one-file version of $_FILES. For the record, there are no validation rules tied to the file upload field.
Any ideas on what is causing the form to lose the additional images?

PHP upload file error code 8

I have a form with works well (upload) for many image files and with diferente size.
But some images are not uploaded to the server.
Problem images have empty $_FILE[name][tmp_name] and $_FILE[name][error] == 8.
In the same time other images (which have a larger or smaller file size) uploading properly.
Have you any ideas?
Thanks.
print_r($_FILES) for normal image
FILES:Array
(
[img] => Array
(
[name] => Array
(
[0] => 1320600215_0_284da_78d5c77a_xl.jpg
)
[type] => Array
(
[0] => image/jpeg
)
[tmp_name] => Array
(
[0] => /var/www/test/data/mod-tmp/phpoqm4qR
)
[error] => Array
(
[0] => 0
)
[size] => Array
(
[0] => 126867
)
)
)
print_r($_FILES) for problem image
FILES:Array
(
[img] => Array
(
[name] => Array
(
[0] => 94689121_1GPPZgCqPmI.jpg
)
[type] => Array
(
[0] =>
)
[tmp_name] => Array
(
[0] =>
)
[error] => Array
(
[0] => 8
)
[size] => Array
(
[0] => 0
)
)
)
Hi error code 8 means:
UPLOAD_ERR_EXTENSION
Value: 8; A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help. Introduced in PHP 5.2.0.
Things that may help:
check if your server has some extra security modules installed that may limit file uploading (eg.Suhosin gives a lot of these issues)
check if your max_upload_filesize and post_max_size params are properly set
try to check if this issue happens with some specific file (eg. big files, for some extensions or some filenames) or if it's completely random
if (isset($_FILES['files']) && !empty($_FILES['files']))
{
date_default_timezone_set("asia/kolkata");
$image=date("YmdHis")."_".$_FILES['files']['name'];
move_uploaded_file($_FILES['files']
['tmp_name'],"uploads/business/".$image);
}

php array building with foreach

I'm making a class that lists files of a given extension inside a folder.
the trouble I'm having is that some files are images and I want to extract more information from those files and not for files that are not images.
I created this foreach that adds an entry to an array. later that array is returnd and contains all the files:
$file_array[] = array(
"basename"=>$file->getBasename(),
"size"=>$file->getSize(), //in bytes
"extension"=>$extension,
"file"=>$filename,
"path"=>$file->getPath(),
in_array(strtolower($extension), array("jpg","jpeg","png","gif")) ? array("info"=>getimagesize($filename)) : null
);
As i said earlier, this works.
the problem that I want to correct is the output:
Array
(
[0] => Array
(
[basename] => 1.JPG
[size] => 56533
[extension] => jpg
[file] => folder\1.JPG
[path] => folder
[0] => Array
(
[info] => Array
(
[0] => 897
[1] => 616
[2] => 2
[3] => width="897" height="616"
[bits] => 8
[channels] => 3
[mime] => image/jpeg
)
)
)
[1] => Array
(
[basename] => 2.JPG
[size] => 56533
[extension] => jpg
[file] => folder\2.JPG
[path] => folder
[0] => Array
(
[info] => Array
(
[0] => 897
[1] => 616
[2] => 2
[3] => width="897" height="616"
[bits] => 8
[channels] => 3
[mime] => image/jpeg
)
)
)
)
the problem I want to correct is that I want to access the file info like $file_array[0]['info'] and not $file_array[0][0]['info']. That second index is useless since there can be only one info for a file.
Any way to correct this?
Then don't add an array around your info key:
'info' => in_array(...) ? getimagesize($filename) : null
$file_array[] = array(
"basename"=>$file->getBasename(),
"size"=>$file->getSize(), //in bytes
"extension"=>$extension,
"file"=>$filename,
"path"=>$file->getPath(),
"info" => in_array(strtolower($extension), array("jpg","jpeg","png","gif")) ? getimagesize($filename) : array()
);
This should work
Your keys are incorrect. Try this. Note that I've added info as an index which sets the value from the condition.
$file_array[] = array(
"basename"=>$file->getBasename(),
"size"=>$file->getSize(), //in bytes
"extension"=>$extension,
"file"=>$filename,
"path"=>$file->getPath(),
'info' => in_array(strtolower($extension), array("jpg","jpeg","png","gif")) ? getimagesize($filename) : null
);

Wikipedia API returns only a tiny set of data?

Hey there,
I'm trying to extract data from Wikipedia articles using its API (http://en.wikipedia.org/w/api.php) from a PHP script, but I always only seem to get a fraction of the real content.
For example, when trying :
$page=get_web_page("http://en.wikipedia.org/w/api.php?action=query&titles=Cat&prop=links&format=txt");
echo $page["content"];
This is what I get :
Array ( [query] => Array ( [pages] => Array ( [6678] => Array ( [pageid] => 6678 [ns] => 0 [title] => Cat [links] => Array ( [0] => Array ( [ns] => 0 [title] => 10th edition of Systema Naturae ) [1] => Array ( [ns] => 0 [title] => 3-mercapto-3-methylbutan-1-ol ) [2] => Array ( [ns] => 0 [title] => Abyssinian (cat) ) [3] => Array ( [ns] => 0 [title] => Actinidia polygama ) [4] => Array ( [ns] => 0 [title] => Adaptive radiation ) [5] => Array ( [ns] => 0 [title] => African Wildcat ) [6] => Array ( [ns] => 0 [title] => African wildcat ) [7] => Array ( [ns] => 0 [title] => Afro-Asiatic languages ) [8] => Array ( [ns] => 0 [title] => Age of Discovery ) [9] => Array ( [ns] => 0 [title] => Agouti signalling peptide ) ) ) ) ) [query-continue] => Array ( [links] => Array ( [plcontinue] => 6678|0|Albino ) ) )
I was requesting the full list of links on the "Cat" article, but I only seem to get the first 10 in alphabetic order.
This happens no matter the format I choose and even from the API itself (see http://en.wikipedia.org/w/api.php?action=query&titles=Cat&prop=links).
What is causing this restriction, and how can I fix it ?
If you look at the API manual, you will see that there is a pllimit option, which specifies how many links you want to be sent. You can get 500, or 5000 if you have a bot account, at one time.
You will see at the end of the data dump you provided the following: [plcontinue] => 6678|0|Albino ). You can provide this information to the server and get back more links from the page, starting from that point. So the next query you make would be
$page=get_web_page("http://en.wikipedia.org/w/api.php?action=query&titles=Cat&prop=links&format=txt&plcontinue=6678|0|Albino");
You will need to keep doing this until the server does not return a plcontinue value.

Manipulating arrays in php

I have an file uploading site, it has an option of uploading through urls, what I am trying to do is whenever a user uploads through url, I check my database if a file exists that was uploaded through same url it displays the download url directly instead of uploading it again.
The data sent to uploading script is in array form like:
Array (
[0] => http://i41.tinypic.com/3342r93.jpg
[1] => http://i41.tinypic.com/28cfub7.jpg
[2] => http://i41.tinypic.com/12dsa32.jpg
)
and the array used for outputing the results is in form like this:
Array
(
[0] => Array
(
[id] => 43
[name] => 3342r93.jpg
[size] => 362750
[descr] =>
[password] =>
[delete_id] => 75CE
[upload_id] => 75F45CAE1
)
[1] => Array
(
[id] => 44
[name] => 28cfub7.jpg
[size] => 105544
[descr] =>
[password] =>
[delete_id] => D392
[upload_id] => 6676FD881
)
[2] => Array
(
[id] => 45
[name] => 12dsa32.jpg
[size] => 49000
[descr] =>
[password] =>
[delete_id] => 54C9
[upload_id] => A58614C01
)
)
Now I want is that if the link http://i41.tinypic.com/28cfub7.jpg is already upload I just add it to output array but maintain it in a order (if the link added was 2nd in array the output result should also show it in 2nd)
So what function should be used to remove the matched urls from input array and a function to add it output array in the order no.
// edited
Yes unset will do the thing but I want to maintain the order:
For example after unsetting the array looks like this:
Array (
[0] => http://i41.tinypic.com/3342r93.jpg
// [1] was removed
[2] => http://i41.tinypic.com/12dsa32.jpg
)
but the output array would be
Array
(
[0] => Array
(
[id] => 43
[name] => 3342r93.jpg
[size] => 362750
[descr] =>
[password] =>
[delete_id] => 75CE
[upload_id] => 75F45CAE1
)
// this will become [1], so how can i add another output[1] and shift other
// items after it to [2], [3] and so on...
[1] => Array
(
[id] => 45
[name] => 12dsa32.jpg
[size] => 49000
[descr] =>
[password] =>
[delete_id] => 54C9
[upload_id] => A58614C01
)
)
Well, you can add it to the output array by doing something like:
$OutArray[2] = $element;
Where $element is another Array with the id, name, size (etc...) elements.
As for removing from the array:
unset($OutArray[2]);
You may want to read Array (PHP manual).
If you have an indexed array, you can remove a value by doing:
unset ($array[2]);
If you want to add an item to an array, use this shorthand of array_push (you don't need to specify an index!):
$array[] = "new object";
All documentation is on php.net/arrays
Why don't use an if statement and/or file_exists() to see if the file is there. If you already have an array with the values then it just won't be uploaded again.

Categories