Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6871189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:46:30+00:00 2026-05-27T03:46:30+00:00

I am working on how to file upload. Its kinda confusing for me due

  • 0

I am working on how to file upload. Its kinda confusing for me due to I am just learning this. I have a database name tblFile for the uploads. I also have a folder on my desktop name upload for the uploads. Then I have a script called filename.php. Here is a little bit of my code that I have. As you can see I most likely got some areas wrong.The uploads are not going in the uploads folder.

$aryImages=array("image/jpeg","image/png");

$aryDocs=array("application/msword","application/pdf","video/x-msvideo");

$filename=filenameSafe($_FILES['upload']['name']);

$fileType=$_FILES["upload"]["type"];

if (in_array($_FILES["upload"]["type"],$aryImages)){
    createThumb($fileType,$_FILES['uploadFile']['tmp_name'],$filename,100,100);
}
elseif (in_array($_FILES["uploadFile"]["type"],$aryDocs)){
    move_uploaded_file($_FILES['uploadFile']['tmp_name'],
              "/home/valerie2/public_html/elinkswap/filename.php/".$filename);

    $aryColumns=array(  "sessionID"=>$curSess,
                        "fileName"=>$filename,
                        "fileType"=>$fileType,
                        "thumbFileName"=>$thumbFilename,
                        "dateCreated"=>date('Y-m-d H:i:s'));
    dbInsert($filename,$aryColumns,$_FILES["upload"]["type"]);
}
else{
    echo "File Uploaded";
}

I am getting confused I have been cramping in php in all different areas into about 16 weeks and at this point everything just seems to be run ons in my head. This is a part of homework but I think i have some files backwards and I am just hoping someone will help me understand what I am doing . Thanks

Edit:
Here is the file that I am working on more:

    <?php


function dbConnect(){
// Connect to the database:
 $hostname="localhost";
 $database="tblFile";
 $mysql_login="valerie2_shuawna";
 $mysql_password="norris";

 if(!($db=mysql_connect($hostname, $mysql_login, $mysql_password))){
    echo"error on connect";
 }
 else{
    if(!(mysql_select_db($database,$db))){
        echo mysql_error();
        echo "<br />error on database connection. Check your settings.";
    }
    else{
                echo "This is the home page. I have successfully made a connection to my database and everything
 is working as it should.";
        }


}

$aryImages=array("image/jpeg","image/png");
$aryDocs=array("application/msword","application/pdf","video/x-msvideo");
$filename=filenameSafe($_FILES['uploads']['name']);
$fileType=$_FILES["uploads"]["type"];
if (in_array($_FILES["uploads"]["type"],$aryImages)){
    createThumb($fileType,$_FILES['uploads']['tmp_name'],$filename,100,100);
}
elseif (in_array($_FILES["uploads"]["type"],$aryDocs)){
    move_uploaded_file($_FILES['uploads']['tmp_name'],
"/home/valerie2/public_html/elinkswap/uploads/".$filename);
    $aryColumns=array("sessionID"=>$curSess,"fileName"=>$filename,"fileType"=>$fileType,"thumbFileName"=>$thumbFilename,"dateCreated"=>date('Y-m-d H:i:s'));
    dbInsert($filename,$aryColumns,$_FILES["upload"]["type"]);
}


    else{

    echo "File Uploaded";
  }
 }
function createThumb($type,$tmpname,$filename,$new_w,$new_h){
    $thumbFilename="tmb-".$filename;
    echo $type;
    echo "<br>".$tmpname;
    if (is_numeric(strpos($type,"jpeg"))){
        $src_img=imagecreatefromjpeg($tmpname);
    }
    if (is_numeric(strpos($type,"png"))){
        $src_img=imagecreatefrompng($tmpname);
    }
    $old_x=imageSX($src_img);
    $old_y=imageSY($src_img);
    if ($old_x > $old_y) {
        $thumb_w=$new_w;
        $thumb_h=$old_y*($new_h/$old_x);
    }
    if ($old_x < $old_y) {
        $thumb_w=$old_x*($new_w/$old_y);
        $thumb_h=$new_h;
    }
    if ($old_x == $old_y) {
        $thumb_w=$new_w;
        $thumb_h=$new_h;
    }
    $dst_img=imagecreatetruecolor($thumb_w,$thumb_h);
    imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
    if (is_numeric(strpos($type,"jpeg"))){
        imagejpeg($dst_img,"/home/valerie2/public_html/elinkswap/uploads/".$thumbFilename);
        imagejpeg($src_img,"/home/valerie2/public_html/elinkswap/uploads/".$filename);
    }
    if (is_numeric(strpos($type,"png"))){
        imagepng($dst_img,"/home/valerie2/public_html/elinkswap/uploads/".$thumbFilename);
        imagepng($src_img,"/home/valerie2/public_html/elinkswap/uploads/".$filename);
    }
    imagedestroy($dst_img);
    imagedestroy($src_img);
    dbInsert($filename,$thumbFilename,$type);
}
function filenameSafe($filename) {
    $temp = $filename;
    // Lower case
    $temp = strtolower($temp);
    // Replace spaces with a ’_’
    $temp = str_replace(" ", "_", $temp);
    // Loop through string
    $result = "";
    for ($i=0; $i<strlen($temp); $i++) {
        if (preg_match('([0-9]|[a-z]|_|.)', $temp[$i])) {
            $result = $result.$temp[$i];
        }
    }
    dbConnect();
    $SQL="SELECT fileID FROM uploads WHERE fileName='".$result."'";
    //echo $SQL;
    $rs=mysql_query($SQL);
    echo mysql_num_rows($rs);
    if(mysql_num_rows($rs)!=0){
        $extension=strrchr($result,'.');
        $result=str_replace($extension,time(),$result);
        $result=$result.$extension;
    }
    return $result;
}

function dbInsert($filename,$thumbFilename,$type){
    dbConnect();
    $SQL="INSERT Into uploads (fileName,thumbFileName,fileType) values('".$filename."','".$thumbFilename."','".$type."')";
    //echo $SQL;
    mysql_query($SQL);


}



?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>File Upload</title>
<link href="styles.css" type="text/css" rel="stylesheet" />
</head>
<body>


<form enctype="multipart/form-data" action="filename.php" method="post">

Select File: <input type="file" name="uploads">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000"/>
<input name="Submit" type="submit" value="uploads">

</form>

But the files still dont load to the upload folder.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:46:30+00:00Added an answer on May 27, 2026 at 3:46 am

    Well, it seems your confusing the $_FILES['upload'] and $_FILES['uploadFile'] names. I ajust all to one name: upload. Let’s see the code:

    First some declarations…

    $aryImages=array("image/jpeg","image/png");
    $aryDocs=array("application/msword","application/pdf","video/x-msvideo");
    
    $filename=filenameSafe($_FILES['upload']['name']);
    $fileType=$_FILES["upload"]["type"];
    

    Then I think you shoul verify the file type BEFORE you generate the thumb, right? Cause if file type isn’t okay, you just don’t create the thumb.

    if (in_array($_FILES["upload"]["type"],$aryDocs)) {
    

    So filetype is okay, now create the thumb…

        if (in_array($_FILES["upload"]["type"],$aryImages)) {
            createThumb($fileType,$_FILES['upload']['tmp_name'],$filename,100,100);
        }
    

    Is heavy recommended to verify all steps like the move_uploaded_file. This function is crucial to the entire script works fine…

        if (move_uploaded_file($_FILES['upload']['tmp_name'],
    "/home/valerie2/public_html/elinkswap/filename.php/".$filename)) {
            $aryColumns=array("sessionID"=>$curSess,"fileName"=>$filename,"fileType"=>$fileType,"thumbFileName"=>$thumbFilename,"dateCreated"=>date('Y-m-d H:i:s'));
    

    Good, now here you verify if your function dbInsert do his job well…

            if (dbInsert($filename,$aryColumns,$_FILES["upload"]["type"])) {
               // Upload OK
            } else {
               // Error inserting on DB
            }
        } else {
            // Error moving file!!
        }
    }
    

    Note that I have not tested this script. I hope it helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone see a problem with this, its not working saying bad file descriptor
I have an Upload File form, the file has (Name nvarchar, FileData varbinary(max)) Name
I have jar file which is signed on my local machine. Its working fine
I am working on an ASP web page that handles file uploads. Only certain
On whatever reason this is not working (says 'file not found'), set in=c:\myprogram\_save cd
we are facing a strange issue. we have a (custom)file upload control in our
I have used a input file code to upload image to my wallpaper site..
I am working on a php site in which we have to upload images
Ive been working on create a file upload form using PHPmailer to send as
I am trying to use Valum's Ajax Upload to do file uploads on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.