PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Feb 25, 2020 1:21 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Thu Feb 02, 2012 6:25 am 
Offline
Forum Commoner

Joined: Fri Nov 04, 2011 9:04 am
Posts: 28
Hi there,

I am currently develop a student database management system for my faculty. I am using the PHP together with MySQL. I am thinking to create an option for the student to upload their profile photo but I could not find any proper instruction of doing that.

Where can I look for that?


Top
 Profile  
 
PostPosted: Thu Feb 02, 2012 11:13 am 
Offline
Forum Commoner

Joined: Fri Nov 04, 2011 9:04 am
Posts: 28
I just thinking to get some sample scripts/instructions where people will register online with their picture uploaded. Then, one will be able to view the profile showing the picture that being uploaded earlier.


Top
 Profile  
 
PostPosted: Sat Feb 04, 2012 5:43 am 
Offline
Forum Commoner

Joined: Fri Nov 04, 2011 9:04 am
Posts: 28
Here's the code processing the file uploading:

Syntax: [ Download ] [ Hide ]
<?php
 /* Script name: uploadFile.php
  * Description: Uploads a file via HTTP with a POST form.
  */

  if(!isset($_POST[‘Upload’]))
  {
    include(“form_upload.inc”);
  }
  else  
  {
    if($_FILES[‘pix’][‘tmp_name’] == “none”)
    {
      echo<p style=’font-weight: bold’>
        File did not successfully upload. Check the
            file size. File must be less than 500K.</p>;
      include(“form_upload.inc”);
      exit();
    }
    if(!ereg(“image”,$_FILES[‘pix’][‘type’]))
    {
      echo<p style=’font-weight: bold’>
        File is not a picture. Please try another
            file.</p>;
      include(“form_upload.inc”);
      exit();
    }
    else  
    {
      $destination=’c:\data’.”\\”.$_FILES[‘pix’][‘name’];
      $temp_file = $_FILES[‘pix’][‘tmp_name’];
      move_uploaded_file($temp_file,$destination);
      echo<p style=’font-weight: bold’>
        The file has successfully uploaded:
            {$_FILES[‘pix’][‘name’]}
            ({$_FILES[‘pix’][‘size’]})</p>;
    }
  }
?>
 


Code for the file upload form:
Syntax: [ Download ] [ Hide ]
<!-- Program Name: form_upload.inc
     Description:  Displays a form to upload a file -->
<html>
<head><title>File Upload</title></head>
<body>
<ol><li>Enter the file name of the product picture you
        want to upload or use the browse button
        to navigate to the picture file.</li>
    <li>When the path to the picture file shows in the
        text field, click the Upload Picture
        button.</li>
</ol>
<div align=”center”><hr />
<form enctype=”multipart/form-data”
        action=”uploadFile.php” method=”POST”>
  <input type=”hidden” name=”MAX_FILE_SIZE”
         value=”500000” />
  <input type=file” name=”pix” size=60/>
  <p><input type=”submit” name=”Upload”
        value=”Upload Picture” />
</form>
</div></body></html>
 


I have no idea where is the file being uploaded to. It is not uploaded to the location as it should be. Please guide me through. Thanks in advance.


Top
 Profile  
 
PostPosted: Sun Feb 19, 2012 4:59 pm 
Offline
DevNet Master
User avatar

Joined: Sun Feb 15, 2009 12:08 pm
Posts: 2794
Location: .za
Syntax: [ Download ] [ Hide ]
$destination=’c:\data’.”\\”.$_FILES[‘pix’][‘name’];

This is the destination; c:\data\imageName.jpg ; Permission could be a reason the files aren't uploading to the specified directory

The code seems like it will give syntax errors; this often happens when copying code from a pdf and the pasting it in a plain text editor; rather type out the code;

_________________
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering


Top
 Profile  
 
PostPosted: Mon Feb 20, 2012 5:27 am 
Offline
DevNet Resident
User avatar

Joined: Sun Sep 03, 2006 5:19 am
Posts: 1579
Location: Sofia, Bulgaria
Huge security hole, can upload any file with any name in any writable folder on the server.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group