Jump to content

what's wrong with this pls?


jesi

Recommended Posts

[code=php:0]<?php
$target_path = "test/";
$target_path = $target_path . basename($_FILES["file"]["name"]);
if ((move_uploaded_file($_FILES["file"]["tmp_name"], $target_path)) && ($_FILES["file"]["type"] == "text/plain") || ($_FILES["file"]["type" == "images/jpeg"))  {
echo "success";
} else {
echo "failed";
}
?>[/code]
if i don't make the third condition it works but i know that it should work it would be a great help if someone can tell me wts wrong with this script
by the i get this error
[quote]Parse error: parse error, unexpected ')', expecting ']' in E:\server\htdocs\upload.php on line 4[/quote]
Link to comment
https://forums.phpfreaks.com/topic/29033-whats-wrong-with-this-pls/
Share on other sites

Could it be the missing left bracket?

if ((move_uploaded_file($_FILES["file"]["tmp_name"], $target_path)) && ($_FILES["file"]["type"] == "text/plain") || ($_FILES["file"]["type"[b][color=red]][/color][/b] == "images/jpeg"))

Also, the logic is off, I believe. The logic is read from left to right. So the way it is written the condition will pass if
(move_uploaded_files is true AND the name is "text/plain")   OR    (the name is "images/jpeg")

I think what you want is this:

if ( move_uploaded_file($_FILES["file"]["tmp_name"], $target_path) && ( ($_FILES["file"]["type"] == "text/plain") || ($_FILES["file"]["type"] == "images/jpeg") ) )

EDIT: I'm surprised that jpeg files would fail with what you had originally. Anyway, try what I posted above, I think that will work for you.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.