/    Sign up×
Community /Pin to ProfileBookmark

Should BE EASY AS!

Hey all, Im using an awsome package to upload multiples files once.

[URL=”http://www.element-it.com/MultiPowUpload.aspx”]http://www.element-it.com/MultiPowUpload.aspx[/URL]

I Need to rename every file to 1.jpg, 2.jpg, 3.jpg etc sequentially.

[CODE]<?php
$file = str_replace(basename($_SERVER[‘PHP_SELF’]),”,($_SERVER[‘PHP_SELF’]));
$uploaddir = $_SERVER[‘DOCUMENT_ROOT’] . $file . “Images/”;

$uploadfile = $uploaddir . basename($_FILES[‘Filedata’][‘name’]);
move_uploaded_file ($_FILES[‘Filedata’][‘tmp_name’], $uploadfile);

[/CODE]

This Uploads all the files to an images folder with the original names.

And when i add this to the above

[CODE]
$count = count($_FILES[‘Filedata’]);

for ($i=1; $i <= $count; $i++) {
rename($uploadfile, $uploaddir . $i. “.jpg”);
};
?>
[/CODE]

It renames the files the way i need them but just the wrong amount of times.

So i guesss my question is What would i ‘count’ to get the right reference number for the loop? eg How many files im uploading.

Iv been on this problem for the past eight hours, im relativley new. Any help would in my books win you a nomination for Nobile Peace prize ?

Thanks in advance

to post a comment
PHP

16 Comments(s)

Copy linkTweet thisAlerts:
@jasonahouleMar 11.2007 — Why don't you just change the name when you move it? You must be looping through the files already, right? Instead of
<i>
</i>$uploadfile = $uploaddir . basename($_FILES['Filedata']['name']);

you can use
<i>
</i>$uploadfile = $uploaddir . basename($_FILES['Filedata'][$i]);
Copy linkTweet thisAlerts:
@bokehMar 11.2007 — [code=php]$count = count(array_keys($_FILES['Filedata']['error'], 0));[/code]That should get you the number of successful uploads.
Copy linkTweet thisAlerts:
@scratch22authorMar 11.2007 — Ok I tried that and no good, Thanks tho.

Any loop i create has to loop through one of the $_FILE['Filedata']['tmp_name' or 'name' etc] arrays.

When i do loop through it shows that theres only one value in here at any one time, which made me think whether the whole page was being loaded once for every file but i dont think it is.
Copy linkTweet thisAlerts:
@scratch22authorMar 11.2007 — Cheers Bokeh but no good.

Heres the latest of the whole script.
[CODE]
<?php

$file = str_replace(basename($_SERVER['PHP_SELF']),'',($_SERVER['PHP_SELF']));
$uploaddir = $_SERVER['DOCUMENT_ROOT'] . $file . "Images/";



$uploadfile = $uploaddir . basename($_FILES['Filedata']['name']);
move_uploaded_file ($_FILES['Filedata']['tmp_name'], $uploadfile);


$count = count(array_keys($_FILES['Filedata']['error'],0));


for ($i=0; $i <= $count; $i++) {
rename($uploadfile, $uploaddir . $i. ".jpg");
};

?> [/CODE]


The value of this $count is 1. (strange);

If It were just this (below), It would put as many images over as i want. Ive tried 16 so far and works great. (BTW this is just a testing script for later use in an admin section);

[CODE]
<?php
$file = str_replace(basename($_SERVER['PHP_SELF']),'',($_SERVER['PHP_SELF']));
$uploaddir = $_SERVER['DOCUMENT_ROOT'] . $file . "Images/";



$uploadfile = $uploaddir . basename($_FILES['Filedata']['name']);
move_uploaded_file ($_FILES['Filedata']['tmp_name'], $uploadfile);
?>
[/CODE]


I find it really strange that this can find all the files being sent, because when I loop, or count, or sizeof, any of the arrays available it only returns

1 name etc.

Again thanks to who have tried.

Im trying to build a gallery admin section that will output an XML from a database for a Flash gallery.
Copy linkTweet thisAlerts:
@bokehMar 11.2007 — Post the whole script.
Copy linkTweet thisAlerts:
@scratch22authorMar 11.2007 — Sorry what i meant is that it only changes one name and the rest are the original names. All the files still get sent.
Copy linkTweet thisAlerts:
@bokehMar 11.2007 — That is not the whole script.
Copy linkTweet thisAlerts:
@scratch22authorMar 11.2007 — lol its the whole processing script.

it works fine without the count or change name code .

If you wanna check out the package it only takes ten mins or so to setup ?
Copy linkTweet thisAlerts:
@scratch22authorMar 11.2007 — Heres the script that calls the uploadproccesing script.

[CODE]<html>
<head>
<title>Adding / Deleting into database</title>
<?php include 'database.php';?>

</head>
<script language="JavaScript">

function mysubmit(type)
{
if(type=='flash')
{
var Flash;
if(document.embeds && document.embeds.length>=1)
Flash = document.getElementById("EmbedFlashFilesUpload");
else
Flash = document.getElementById("FlashFilesUpload");
Flash.SetVariable("uploadUrl", "winupload.php");
Flash.SetVariable("SubmitFlash", "");
var FormObj = document.getElementById("myform");
FormObj.action = "winupload.php";
return true;
}
else
{
var FormObj = document.getElementById("myform");
FormObj.action = "winupload.php";
return true;
}
}
</script>
<body>

<div id= "input">
<br><b>Insert text here</b>
<form action="insert.php" method="post">
<input type="text" name="value" />
<input type="submit" name="submit" value="Insert">
</form>
</div>



<div id="output">
<br><br>
<form action="delete.php" method="post">
<select name="gallery" title="Galleries">
<?php
$result = mysql_query("SELECT * FROM testtable");

while ($rows = mysql_fetch_array($result)) {
$id = $rows['id'];
$names = $rows['testField'];
echo "<option id="$id">$names</option><br>";
};
?>
</select>
<input type="submit" name="delete" value="Delete">
</form>

<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" size="30">
<input type="submit" value="Submit">
</form>



<form method="post" action="output.php">
<input type="submit" name="upload" value="Write XML">
</form>


<OBJECT id="FlashFilesUpload" codeBase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"
width="450" height="300" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" VIEWASTEXT>
<!-- Replace symbols " with the &quot; at all parameters values and
symbols "&" with the "%26" at URL values or &amp; at other values! -->
<PARAM NAME="FlashVars" VALUE="uploadUrl=&uploadButtonVisible=No">
<PARAM NAME="BGColor" VALUE="#F8F6E6">
<PARAM NAME="Movie" VALUE="ElementITMultiPowUpload1.6.swf">
<PARAM NAME="Src" VALUE="ElementITMultiPowUpload1.6.swf">
<PARAM NAME="WMode" VALUE="Window">
<PARAM NAME="Play" VALUE="-1">
<PARAM NAME="Loop" VALUE="-1">
<PARAM NAME="Quality" VALUE="High">
<PARAM NAME="SAlign" VALUE="">
<PARAM NAME="Menu" VALUE="-1">
<PARAM NAME="Base" VALUE="">
<PARAM NAME="AllowScriptAccess" VALUE="always">
<PARAM NAME="Scale" VALUE="ShowAll">
<PARAM NAME="DeviceFont" VALUE="0">
<PARAM NAME="EmbedMovie" VALUE="0">

<PARAM NAME="SWRemote" VALUE="">
<PARAM NAME="MovieData" VALUE="">
<PARAM NAME="SeamlessTabbing" VALUE="1">
<PARAM NAME="Profile" VALUE="0">
<PARAM NAME="ProfileAddress" VALUE="">
<PARAM NAME="ProfilePort" VALUE="0">

<!-- Embed for Netscape,Mozilla/FireFox browsers support. Flashvars parameters are the same.-->
<!-- Replace symbols " with the &quot; at all parameters values and
symbols "&" with the "%26" at URL values or &amp; at other values! -->
<embed bgcolor="#F8F6E6" id="EmbedFlashFilesUpload" src="ElementITMultiPowUpload1.6.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="400" height="350" flashvars="uploadUrl=&uploadButtonVisible=No">
</embed>
</OBJECT>

<br>

<input onClick="mysubmit('flash');" id="myform" type="button" value="Send Files" name="myform" />

</div>
</body>
</html>
[/CODE]
Copy linkTweet thisAlerts:
@scratch22authorMar 11.2007 — OK bokeh maybe im having Permission probs, just download your image gallery script from your site and when i uploaded an image i got the permission denied error.

But if i didn have permission denied wouldn't that mean i would have probs uploading from my script? as i havent set any permissions for any of those folders?

Anyways im downloading Filezilla server right now to set permissions to my whole localhost. as dreamweaver seams to have trouble with permission setting.
Copy linkTweet thisAlerts:
@bokehMar 11.2007 — If you wanna check out the package it only takes ten mins or so to setup ?[/QUOTE]The package has nothing to do with PHP... and the processing script you are using is not for multiple uploads. You need concordance between your clientside and serverside scripts so they can work in harmony.
Copy linkTweet thisAlerts:
@scratch22authorMar 11.2007 — OK here is everything that has anything to do with the uploads.

Where the "upload Images" resides.

insertAdmin.php

NOTE: Everything above the <OBJECT> has nothing to do with multiple uploads EXCEPT the <javascript> in the header.
[CODE]<html>
<head>
<title>Adding / Deleting into database</title>
<?php include 'database.php';?>

</head>
<script language="JavaScript">

function mysubmit(type)
{
if(type=='flash')
{
var Flash;
if(document.embeds && document.embeds.length>=1)
Flash = document.getElementById("EmbedFlashFilesUpload");
else
Flash = document.getElementById("FlashFilesUpload");
Flash.SetVariable("uploadUrl", "winupload.php");
Flash.SetVariable("SubmitFlash", "");
var FormObj = document.getElementById("myform");
FormObj.action = "winupload.php";
return true;
}
else
{
var FormObj = document.getElementById("myform");
FormObj.action = "winupload.php";
return true;
}
}
</script>
<body>

<div id= "input">
<br><b>Insert text here</b>
<form action="insert.php" method="post">
<input type="text" name="value" />
<input type="submit" name="submit" value="Insert">
</form>
</div>



<div id="output">
<br><br>
<form action="delete.php" method="post">
<select name="gallery" title="Galleries">
<?php
$result = mysql_query("SELECT * FROM testtable");

while ($rows = mysql_fetch_array($result)) {
$id = $rows['id'];
$names = $rows['testField'];
echo "<option id="$id">$names</option><br>";
};
?>
</select>
<input type="submit" name="delete" value="Delete">
</form>

<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" size="30">
<input type="submit" value="Submit">
</form>



<form method="post" action="output.php">
<input type="submit" name="upload" value="Write XML">
</form>


<OBJECT id="FlashFilesUpload" codeBase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"
width="450" height="300" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" VIEWASTEXT>
<!-- Replace symbols " with the &quot; at all parameters values and
symbols "&" with the "%26" at URL values or &amp; at other values! -->
<PARAM NAME="FlashVars" VALUE="uploadUrl=&uploadButtonVisible=No">
<PARAM NAME="BGColor" VALUE="#F8F6E6">
<PARAM NAME="Movie" VALUE="ElementITMultiPowUpload1.6.swf">
<PARAM NAME="Src" VALUE="ElementITMultiPowUpload1.6.swf">
<PARAM NAME="WMode" VALUE="Window">
<PARAM NAME="Play" VALUE="-1">
<PARAM NAME="Loop" VALUE="-1">
<PARAM NAME="Quality" VALUE="High">
<PARAM NAME="SAlign" VALUE="">
<PARAM NAME="Menu" VALUE="-1">
<PARAM NAME="Base" VALUE="">
<PARAM NAME="AllowScriptAccess" VALUE="always">
<PARAM NAME="Scale" VALUE="ShowAll">
<PARAM NAME="DeviceFont" VALUE="0">
<PARAM NAME="EmbedMovie" VALUE="0">

<PARAM NAME="SWRemote" VALUE="">
<PARAM NAME="MovieData" VALUE="">
<PARAM NAME="SeamlessTabbing" VALUE="1">
<PARAM NAME="Profile" VALUE="0">
<PARAM NAME="ProfileAddress" VALUE="">
<PARAM NAME="ProfilePort" VALUE="0">

<!-- Embed for Netscape,Mozilla/FireFox browsers support. Flashvars parameters are the same.-->
<!-- Replace symbols " with the &quot; at all parameters values and
symbols "&" with the "%26" at URL values or &amp; at other values! -->
<embed bgcolor="#F8F6E6" id="EmbedFlashFilesUpload" src="ElementITMultiPowUpload1.6.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="400" height="350" flashvars="uploadUrl=&uploadButtonVisible=No">
</embed>
</OBJECT>

<br>

<input onClick="mysubmit('flash');" id="myform" type="button" value="Send Files" name="myform" />

</div>
</body>
</html>

[/CODE]


Here is a script which up untill now I thought was the processing script.

winupload.php
[CODE]<?php

include 'database.php';

$file = str_replace(basename($_SERVER['PHP_SELF']),'',($_SERVER['PHP_SELF']));
$uploaddir = $_SERVER['DOCUMENT_ROOT'] . $file . "Images/";



$uploadfile = $uploaddir . basename($_FILES['Filedata']['name']);
move_uploaded_file ($_FILES['Filedata']['tmp_name'], $uploadfile);


$count = count(array_keys($_FILES['Filedata']['error'],0)); //This returns an error btw -> Warning: array_keys() [function.array-keys]: The first argument should be an array in C:wampwwwTestingtestAdminwinupload.php on line 14;


for ($i=0; $i <= $count; $i++) {
rename($uploadfile, $uploaddir . $i. ".jpg");
};

?> [/CODE]


And the last one

results.php (Dont know what its doing there, I dont think its called upon because it doest ever show);
[CODE]<?php

for($i=0; $i<count($_POST); $i++)
{
if(isset($_POST["MultiPowUploadFileName_". $i]))
{
echo "File with name " . $_POST["MultiPowUploadFileName_". $i]. " and size " . $_POST["MultiPowUploadFileSize_" . $i] . " uploaded successfully<br>";
}
}
?>[/CODE]



Thats everything to do with anything to do with multiple uploads in this directory.

Sorry for my misunderstanding, maybe i should just become a brain surgeon instead.

Thanks so much for you help, I if you can show me what concordence would be in this situation, It would be much appreicated.
Copy linkTweet thisAlerts:
@bokehMar 11.2007 — Use SmartFTP to update your directory permissions.

Put the following line in your PHP script and post the output here.[code=php]echo'<pre>';print_r($_FILES);echo'</pre>';[/code]
Copy linkTweet thisAlerts:
@scratch22authorMar 11.2007 — [22:14:46] SITE CHMOD 777 insertAdmin.php

[22:14:46] 504 Command not implemented for that parameter

So Yep it is permissions.
Copy linkTweet thisAlerts:
@scratch22authorMar 11.2007 — I have now gone played with all my permissions and now cant access anything. Thanks again for your time guys.

The past 15 hours have been somewhat stimulating but now I must state :

"Im going dooown in a blaze of glory",

Ill be back tomorrow!

Thnks again.
Copy linkTweet thisAlerts:
@scratch22authorMar 12.2007 — Well after a refreshing restore and good sleep, I just figured id use scandir after the images had uploaded to get the amount of files needed.

Now off to resize them all and create a thumbnail which would be 1-b.jpg, then to set a variable 1 if portraiat and 0 if landscape. Ahh the joys of progression.

Cya~
×

Success!

Help @scratch22 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...