Temporary link Download

Ask about a PHP problem here.
Ehrmantraut
Posts: 26
Joined: Tue Jul 23, 2013 2:29 am

Re: Temporary link Download

Post by Ehrmantraut »

Temor wrote:What happens if you remove the quotes around $expiry in your upload query?
  mysql_query("INSERT INTO files (file_name, file_expiry) VALUES ('{$file_name}','{$expiry}')");
  mysql_query("INSERT INTO files (file_name, file_expiry) VALUES ('{$file_name}',{$expiry})");
It is, after all, an integer, and should be treated as such. Maybe SQL thinks you're trying to insert a string and defaults to 0.
if you remove the quotes from around $expiry the file doesn't show on file_list.php page.



I'm beginning to wonder if I should just give up on this. You guys are putting a lot of time into this which may I said I really appreciate. but, at the same time it seems to be one step forward two steps back. let me know if you want to continue or not? :)
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Temporary link Download

Post by Temor »

This is what I do on my free-time. I will never stop helping here! :)

/Edit; I'll look at your code with fresh eyes tomorrow. There's probably a typo or something somewhere.
ScTech
Posts: 92
Joined: Sat Aug 24, 2013 8:40 pm

Re: Temporary link Download

Post by ScTech »

We are here to help :) Try putting this under your opening PHP tag at the top of upload.php
error_reporting(E_ALL);
ini_set('display_errors', 1);
<?php while(!$succeed = try()); ?>
Ehrmantraut
Posts: 26
Joined: Tue Jul 23, 2013 2:29 am

Re: Temporary link Download

Post by Ehrmantraut »

ScTech wrote:We are here to help :) Try putting this under your opening PHP tag at the top of upload.php
error_reporting(E_ALL);
ini_set('display_errors', 1);

The only error I'm getting with error reporting turned on is Notice: Undefined variable: expiry in /home/davestec/public_html/tutorial/upload.php on line 56.
ScTech
Posts: 92
Joined: Sat Aug 24, 2013 8:40 pm

Re: Temporary link Download

Post by ScTech »

Found the issue in upload.php :) You can go ahead and remove those lines I told you to put in if it works.
if (in_array($file_ext, $allowed_ext) ===false){
$errors[] = 'File extension not allowed';
Right here you are not ending the bracket until later on so you are only defining $expiry if they uploaded a file with the wrong extension.
<?php while(!$succeed = try()); ?>
Ehrmantraut
Posts: 26
Joined: Tue Jul 23, 2013 2:29 am

Re: Temporary link Download

Post by Ehrmantraut »

ScTech wrote:Found the issue in upload.php :) You can go ahead and remove those lines I told you to put in if it works.
if (in_array($file_ext, $allowed_ext) ===false){
$errors[] = 'File extension not allowed';
Right here you are not ending the bracket until later on so you are only defining $expiry if they uploaded a file with the wrong extension.
Below is the way I have my upload.php file now and it seems to be working. :)

File Name: upload.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>Upload a File</title>
    <style type="text/css">
table {
border-collapse:collapse;
}
 
table, td, th {
border:1px solid #999;
height:43px;
}
    </style>
    </head>
    <body>
    <?php
   
    include('assets/inc/init.inc.php');
   
    if (isset($_POST['expiry'], $_FILES['file'])){
        $errors = array();
        $allowed_ext = array("mp3","doc","txt","jpg","jpeg","gif","png");
       
        $file_name = mysql_real_escape_string($_FILES['file']['name']);
        $file_ext  = strtolower(end(explode('.',$file_name)));
        $file_tmp  = $_FILES['file']['tmp_name'];
 
 
                 if (in_array($file_ext, $allowed_ext) ===false){
         		     $errors[] = 'File extension not allowed';
         		     
         	}
                 
                if(empty($_POST['expiry'])) {
                        $expiry = time() + (10 * 60);
                } else {    
                 
                        if(!ctype_digit($_POST['expiry'])) {        
                                $errors[] = 'Value is not an integer.';                   
                        } else {      
                        
                        $expiry = time() + ($_POST['expiry'] * 60);
                        
                }
                
                }  
         
       		
        
         
 
         if (empty($errors)) {
 
        mysql_query("INSERT INTO files (file_name, file_expiry) VALUES ('{$file_name}',{$expiry})");
        
        move_uploaded_file($_FILES['file']['tmp_name'], "assets/files/{$_FILES['file']['name']}");
       
        echo "<p>". htmlentities($_FILES['file']['name']) ." has been successfully uploaded.<p>";
         
                     
                 } else {
         foreach ($errors as $error){
         echo $error,'<br /><br />';
         
     
         
   }
       
 }
       
}                
?>
      <div>
      <form action="" method="post" enctype="multipart/form-data">
      <table>
       
      <tr>
      <td><b>Set Expiry Time:</b> <input type="text" name="expiry" size="6" /> <b>Minutes Only<b></td>
      </tr>
     
      <tr>
      <td><b>Choose a file:</b> <input type="file" name="file" /></td>
      </tr>
     
       <tr>
      <td><input type="submit" value="Upload!" /></td>
      </tr>
     
      <tr>
      <td><p><a href="file_list.php">Click here</a> to download your time sensitive file, or files.</p></td>
      </tr>
 
    </table>
    </form>
    </div>
    </body>
    </html>

I moved the bracket up for the following code and it seems to be working perfect now. :)
if (in_array($file_ext, $allowed_ext) ===false){ 
$errors[] = 'File extension not allowed';
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Temporary link Download

Post by Temor »

Hooray!
Ehrmantraut
Posts: 26
Joined: Tue Jul 23, 2013 2:29 am

Re: Temporary link Download

Post by Ehrmantraut »

Temor wrote:Hooray!
lol, Temor I'm glad its finally working as well. Thanks again guys for your help it really is appreciated shame there isn't more folks like yourselves on the internet willing to help with coding issues. :)
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Temporary link Download

Post by Temor »

davestechuk wrote:
Temor wrote:Hooray!
lol, Temor I'm glad its finally working as well. Thanks again guys for your help it really is appreciated shame there isn't more folks like yourselves on the internet willing to help with coding issues. :)
We're a rare breed ;)
Ehrmantraut
Posts: 26
Joined: Tue Jul 23, 2013 2:29 am

Re: Temporary link Download

Post by Ehrmantraut »

Temor wrote:
davestechuk wrote:
Temor wrote:Hooray!
lol, Temor I'm glad its finally working as well. Thanks again guys for your help it really is appreciated shame there isn't more folks like yourselves on the internet willing to help with coding issues. :)
We're a rare breed ;)

lol, Thanks again I appreciate it.
Post Reply