Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | PHP Help!

You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > General IT Discussion

PHP Help!
Reply
 
Thread Tools
Old 14-03-2005, 11:05   #1
Strzelecki
Inactive
 
Join Date: Jan 2004
Location: Essex
Age: 43
Services: 80/20Mbps FTTC on Freeola
Posts: 871
Strzelecki has reached the bronze age
Strzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze age
PHP Help!

Ok, I'm in the process of creating a php script to upload multiple files, give them a unique id and store them on the server for download via WAP, hit a wall though in that for some reason I can't upload files over 10Kb in size, MAX_UPLOAD in php.ini is set to the default 8M (Scripts on i-web but working on it in uni) Apache timeout is 30s and uploads set to 2M, sorry for the sloppy code (some doesn't need to be there any more) but can anyone spot the problem?

PHP Code:
<?php
include 'config.php'; //load the standard variables


$num_files = count($_FILES['upfile']['name']); //same as above but for no files
if( $num_files < 1 ) 
{
   echo(
"Error! No files to upload... Exiting");  
   exit();
}

  for( 
$idx=0; $idx < $num_files; $idx++ ){ //loops upload code
    
    
$src = $_FILES['upfile']['tmp_name'][$idx]; //grabs array temp file name
    
$ext = strtolower(end(explode(".", $_FILES['upfile']['name'][$idx]))); //converts file name to lower case
    
$filnavn = $_FILES['upfile']['name'][$idx];        
    
$fileid = rand(10000, 99999); //creates a unique ID number for file,   
    //$fileid = substr(microtime() - time() * 2, 12); //another ID Creator method but zeros get clipped off(?) could cause problems. takes current time in millsecs, minus time in seconds to give last 4 millsec no's (take longer that a millsec to upload file and process, so should be unique)
    
$nytNavn = $fileid.".".$ext; //full file name (unique ID plus extension)
    
if(substr($fileid,5)== 0)
        
autom($wapurl,$urltoindex);

   
        
$dst = $_SERVER['DOCUMENT_ROOT']. '/prin/u1r08/wap/uploaded/' . $nytNavn; //set destination directory of file (to be changed to variable link to config.hphp)
    
        
copy($src, $dst);
        
clearstatcache();
        
usleep(500);
        
$fsize = filesize($dst);
        
        if((
$fsize >= $allowedsize) OR $ext=="php" OR $ext=="htm" OR $ext=="html") { //invalid uploads protection.
            
unlink("uploaded/$nytNavn");
            echo(
"<div align=center>File not uploaded, invalid file type.</div>");
        }
        else { 
//upload
            
            
$min = $timeallowed/60; //Time allowed to keep file.
            
$hours = $min/60;
            echo(
"<div align=center>".$_FILES['upfile']['name'][$idx]." upload success! Go to $wapurl using your mobile and enter this number: $fileid<br><br></div>");
            
                
//Insert uploaded file info into database.
    
    
             
$sql = ("INSERT INTO uploads(idnumber,filename,uptime) VALUES('$fileid','$nytNavn','".time()."')");
                
mysql_query($sql, $db);
            
        }
    }
            
        echo(
"<br><a href='$urltoindex/index.php'>Upload a new file</a>");
    
?>
The error that gets thrown is:
Quote:
Warning: filesize(): Stat failed for /var/www/htdocs/prin/u1r08/wap/uploaded/38170.jpg (errno=2 - No such file or directory) in /var/www/htdocs/prin/u1r08/wap/uploadfile.php on line 29
It's like it looping fast that the file is being stored or something?
Strzelecki is offline   Reply With Quote
Advertisement
Old 14-03-2005, 11:08   #2
Bifta
Inactive
 
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
Bifta has a nice shiny starBifta has a nice shiny star
Bifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny star
Re: PHP Help!

what's DOCUMENT_ROOT set to in config.php? (in fact, can you paste that file too?)
Bifta is offline   Reply With Quote
Old 14-03-2005, 11:12   #3
Strzelecki
Inactive
 
Join Date: Jan 2004
Location: Essex
Age: 43
Services: 80/20Mbps FTTC on Freeola
Posts: 871
Strzelecki has reached the bronze age
Strzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze age
Re: PHP Help!

DOCUMENT_ROOT is a php reserved variable to automatically fine out the root, but here's config.php anyway:
PHP Code:
<?php

require_once("class.php");


//EDIT HERE START

$dbserver = "bilbo.teach.cs.keele.ac.uk:3306";
$username = "u1r08";
$password = "xxxxxxx";
$database = "wap";
$wapurl = "http://www.teach.cs.keele.ac.uk/prin/u1r08/wap/wap.php";
$urltoindex = "http://www.teach.cs.keele.ac.uk/prin/u1r08/wap";             //path where the script files reside in remember NO trailing slash
$hostpage = "http://www.teach.cs.keele.ac.uk/prin/u1r08/wap/uploaded/"; // directory on server where files are saved remember trailing slash
$timeallowed = 360;         //seconds the file should remain on the server
$allowedsize = 2097152;         //allowed size in bytes


//EDIT HERE END



$db = mysql_connect($dbserver, $username, $password);


mysql_select_db($database,$db);

?>
Strzelecki is offline   Reply With Quote
Old 14-03-2005, 11:22   #4
Bifta
Inactive
 
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
Bifta has a nice shiny starBifta has a nice shiny star
Bifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny star
Re: PHP Help!

Without wanting to state the obvious, it looks like it's either uploading the file into a different path than the one filesize is looking for or it's not uploading it at all, sorry, I can't be anymore help than that, I'm sure Richard M or someone can put you right.
Bifta is offline   Reply With Quote
Old 14-03-2005, 11:24   #5
Strzelecki
Inactive
 
Join Date: Jan 2004
Location: Essex
Age: 43
Services: 80/20Mbps FTTC on Freeola
Posts: 871
Strzelecki has reached the bronze age
Strzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze age
Re: PHP Help!

thing is it works fine for file 9.99Kb or less and it is putting them in the right place, why would it change for a file larger than that?
Strzelecki is offline   Reply With Quote
Old 14-03-2005, 11:32   #6
Bifta
Inactive
 
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
Bifta has a nice shiny starBifta has a nice shiny star
Bifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny star
Re: PHP Help!

Quote:
Originally Posted by Strzelecki
thing is it works fine for file 9.99Kb or less and it is putting them in the right place, why would it change for a file larger than that?
If you're on NTL it might (fairly unlikely though) be the HTTP upload failing due to the transparent cache,
Bifta is offline   Reply With Quote
Old 14-03-2005, 11:35   #7
Strzelecki
Inactive
 
Join Date: Jan 2004
Location: Essex
Age: 43
Services: 80/20Mbps FTTC on Freeola
Posts: 871
Strzelecki has reached the bronze age
Strzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze age
Re: PHP Help!

Nope, I'm at uni now using their internal system straight to the webserver, does the same thing on NTL though.
Strzelecki is offline   Reply With Quote
Old 14-03-2005, 11:38   #8
Bifta
Inactive
 
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
Bifta has a nice shiny starBifta has a nice shiny star
Bifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny star
Re: PHP Help!

Has it got any other files, (like class.php) I can test it here if you like.
Bifta is offline   Reply With Quote
Old 14-03-2005, 11:42   #9
Strzelecki
Inactive
 
Join Date: Jan 2004
Location: Essex
Age: 43
Services: 80/20Mbps FTTC on Freeola
Posts: 871
Strzelecki has reached the bronze age
Strzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze age
Re: PHP Help!

Not really, all it has is config.php, the upload page index.php and the processor uploadfile.php plus a simple table in a MySQL database.
class.php
PHP Code:
<?php

function autom($wapurl, $indexurl){
        
        
$msg = "wapurl: $wapurl\n\n";
        
$msg .="indexurl: $indexurl";
}
?>
plus index.php
PHP Code:
<?php 
include 'config.php';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SagemHelp.info WAP uploader</title>
</head>

<body>
<table width="100%"  border="0">
  <tr>
    <td width="18%" height="21">&copy;SagemHelp.info</td>
    <td width="82%">&nbsp;</td>
  </tr>
  <tr>
    <td height="201">&nbsp;</td>
    <td><form enctype="multipart/form-data" action="uploadfile.php" method="POST">
<input name="upfile[]" type="file"><br>
<input name="upfile[]" type="file"><br>
<input name="upfile[]" type="file"><br>
<input type="submit" value="Send Files">
<input type="reset" value="reset">
</form>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>
Strzelecki is offline   Reply With Quote
Old 14-03-2005, 11:50   #10
Bifta
Inactive
 
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
Bifta has a nice shiny starBifta has a nice shiny star
Bifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny star
Re: PHP Help!

what about require_once("class.php"); in config.php ?
Bifta is offline   Reply With Quote
Old 14-03-2005, 11:55   #11
HxBro
Inactive
 
Join Date: Jan 2005
Posts: 5
HxBro is an unknown quantity at this point
Re: PHP Help!

couple of things, fileid won't be random enough, i use :

$server_filename = md5(microtime() . $_FILES['upfile']['name']) . $extension;

for random filenames

2nd, is the directory /var/www/htdocs/prin/u1r08/wap/uploaded/ actually there and read/writeable by the user the webserver runs as

3rd, try using move_uploaded_file($_FILES['upfile']['tmp_name'][$idx], $dst)

instead of the copy
HxBro is offline   Reply With Quote
Old 14-03-2005, 12:03   #12
Strzelecki
Inactive
 
Join Date: Jan 2004
Location: Essex
Age: 43
Services: 80/20Mbps FTTC on Freeola
Posts: 871
Strzelecki has reached the bronze age
Strzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze age
Re: PHP Help!

Quote:
Originally Posted by Strzelecki
class.php
PHP Code:
<?php

function autom($wapurl, $indexurl){
        
        
$msg = "wapurl: $wapurl\n\n";
        
$msg .="indexurl: $indexurl";
}
?>
__________________

Quote:
Originally Posted by HxBro
couple of things, fileid won't be random enough, i use :

$server_filename = md5(microtime() . $_FILES['upfile']['name']) . $extension;
can't do that, has to be a string a 4 numbers, these are entered using a mobile phone via WAP, so using a short string of numbers is easy for the user.

Quote:
Originally Posted by HxBro
2nd, is the directory /var/www/htdocs/prin/u1r08/wap/uploaded/ actually there and read/writeable by the user the webserver runs as
yep, as stated, works fine for smaller files so must be, CHMODed to 777

Quote:
Originally Posted by HxBro
3rd, try using move_uploaded_file($_FILES['upfile']['tmp_name'][$idx], $dst)

instead of the copy
Tried that, does exactly the same thing! Sorry about this, been driving me mad, probably something simple too!
Strzelecki is offline   Reply With Quote
Old 14-03-2005, 12:35   #13
Richard M
Inactive
 
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 47
Posts: 6,343
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Re: PHP Help!

Why are you using usleep()?
Richard M is offline   Reply With Quote
Old 14-03-2005, 13:11   #14
Strzelecki
Inactive
 
Join Date: Jan 2004
Location: Essex
Age: 43
Services: 80/20Mbps FTTC on Freeola
Posts: 871
Strzelecki has reached the bronze age
Strzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze age
Re: PHP Help!

Oops that slipped in from an earlier effort makes no difference on this loop though.
Strzelecki is offline   Reply With Quote
Old 14-03-2005, 13:15   #15
Richard M
Inactive
 
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 47
Posts: 6,343
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Re: PHP Help!

If you are able to wait until after 6 I'll post some of my own code which works.
Richard M is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:35.


Server: lithium.zmnt.uk
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum