2
My code:
//return > 0 is ok!
function _fileinput($name) {
var_dump($name);
$input['arquivo'] = $_FILES["$name"]["name"];
$input['arquivo'] = strtolower(str_replace("h","",$input['arquivo']));
$input['mimetype'] = $_FILES["$name"]["type"];
$input['temp'] = $_FILES["$name"]["tmp_name"];
$input['mimetypes'] = array("image/jpeg", "image/png");
$input['extencoes'] = array(".jpg", ".jpeg", ".png");
$input['extencao'] = strtolower(end(explode(".",$input['arquivo'])));
$input['mimetype'] = strtolower($input['mimetype']);
$input['novo'] = "[fi]"."[".date('Y-m')."]"."[".strtolower($name)."]"."[".rand(1000,9999)."]".".".$input['extencao'];
var_dump($input);
$x = 0;
if ((array_search($input['extencao'], $input['extencoes']) !== FALSE) AND (array_search(mimetype, $input['mimetypes']) !== FALSE)) {
$x++;
}
else {
$x = 0;
}
var_dump($x);
list($largura, $altura) = getimagesize($input['temp']);
if ($largura == "" || $altura == "") {
$x = 0;
}
else {
$x++;
}
var_dump($x);
if ($x == 2) {
return $input['novo'];
}
else {
return 0;
}
var_dump($x);
}
Pastebin version:
Mode of use:
$fileinput = _fileinput("foto");
if ($fileinput > 0) {
echo $fileinput; //nome para o arquivo
}
else {
echo "deny upload!";
}
Problem:
Does not return the new name for the file, the function in Pastebin does not work, why ?
Code references:
I suggest that you post the Pastebin code here, many who can help you, may not have access to this site. I myself, at the moment, do not have access. To know what to post from your code, I recommend you read How to create a Minimum, Complete and Verifiable example
– user28595
Entered as informed
– Barack
Without much analysis, I suggested that you remove double quotes from within straight parentheses that contain variable names -
$_FILES["$name"]["name"]
for$_FILES[$name]["name"]
- Do this for the whole script, there are several parts of code where variables appear in quotes within these parentheses.– Edilson
strtolower(end(explode(".",$input['arquivo'])));
This here generates a Warning.– rray
The problem was not only this, there were others related to logic.
– Edilson