Hello,
first post , and asking for help im afraid. Very new to PHP, was making good progress I thought , but im stuck with this part. I have a uploading form that works perfectly and uploads everything to "uploads/images" . What Im trying to do is upload .txt or .rtf files to "uploads/text" and .jpg and .gif's to "uploads/images . I thought this wasnt going to be too difficult but im totally stuck and have spent hours trying to solve this. If anyone could help at all and show my what I'm doing wrong, Id be very very grateful!
This is the code as it stands. Right now, it ALWAYS goes to "uploadfail.php" and the file does not upload. If I remove all the code relating to filetype then both the text and image files succesully upload and I go to "uploadsucess.php"
Code: <?
require('connection.php');
//my_sql_real..... makes it safe against mysql injection
$title = mysql_real_escape_string($_POST['title']);
$date = mysql_real_escape_string($_POST['date']);
$author = mysql_real_escape_string($_POST['author']);
$description = mysql_real_escape_string($_POST['description']);
$type = mysql_real_escape_string($_POST['type']);
$imgName = $_FILES['pic']['name'];
$imgTmp = $_FILES['pic']['tmp_name'];
$imgSize = $_FILES['pic']['size'];
$imgType = $_FILES['pic']['type'];
$maxFileSize = 200000;
if ($imgType == "image/jpeg" || $imgType == "image/gif" || $imgType == "application/rtf" || $imgType == "application/x-rtf" || $imgType == "text/richtext" || $imgType == "text/plain" ) {
$error = "";
} else {
$error = "type";
}
if ($imgType == "image/jpeg" || $imgType == "image/gif" ) {
$filetype = "image";
}
if ($imgType == "application/rtf" || $imgType == "application/x-rtf" || $imgType == "text/richtext" || $imgType == "text/plain" ) {
$filetype = "text";
} else {
$filetype = "other";
}
if ($imgSize > $maxFileSize) {
$error = "size";
}
if ($error == "" && $imgName != "" && $filetype == "image" ) {
$filePath = "uploads/images/".$imgName;
move_uploaded_file($imgTmp, $filePath);
if ($error == "" && $imgName != "" && $filetype == "text" ) {
$filePath = "uploads/text/".$imgName;
move_uploaded_file($imgTmp, $filePath);
//another securtiy measure sprintf
$query = sprintf("INSERT INTO gallery(title,date,author,type,description,path) VALUES ('%s' , '%s' ,'%s' ,'%s' ,'%s' ,'%s' )", $title,$date,$author,$type,$description,$filePath);
if (!mysql_query($query, $connect)) {
die();
} else {
header("Location: uploadsuccess.php");
}
}
} else {
header("Location: uploadfail.php");
}
?>
help with variable
I've got a problem, i want to echo some images depending on the $id, however for me to get that id i have to extract it from a query. So i've done that, but i want to extract all id's (not just 1), so
Will this protect from mysql injection?
I do not want anything like DROP TABLE to work or any type of coding.. Heres my code.. is it secure? if not, please help:Code:
Help with ORDER BY
Hello. I would like to order by ascending States, then Cities, then Gyms in the following code, but I can't figure it out. If anyone could help, I would truly appreciated it! if(isset($countryid))
Not sure why this script is not working?
Hi I am new to php programing and I was trying to make up a simple script like a captcha but I cannot get the validation part of it working. I think it should work but it is not. Anyone know what is
Dynamic links in an include file
I am working on a small piece of code that counts records from a database and displays the result to the user. Everything works fine, except I am running into difficulties with dynamic links.The code
Multithreading design
HiI have come up with a Singleton class that manages a pool of database connections. Basically the pool is a queue in which I have stored some connection objects. When ever a client calls any of the
Vertical Alligning - Not working in 1 cell?
<?phpecho "<table id=\"valign\" width=\"60%\" style=\"border:1px solid #EEE;\">";echo "<tr><td
Developing Ajax-enabled ASP.Net applications for the iPhone
I would like to develop Ajax web applications using Visual Studio that are optimized for the iPhone. There are a few resources on the web showing how this can be done. However, these tend to be
What are causes of a connection-timeout with fopen()?
Hello! Here is the situation: The server I host my website on just upgraded it's PHP build from 4.4.* to 5.2.4. Not just PHP was upgraded, MySQL, postGres, and (I think) Apache were upgraded as well.
Baffled by Undefined Index in Simple Array: Please Help!
Hello. I have a form which posts an array to this script. However, I can't seem to access the values in the array; I keep getting an undefined index. Something is not right, but the code is so simple!